🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.jbuilder.java.swing
10 messages
10 total messages Started by Ted Byers Fri, 19 Mar 2004 15:32
Can I make an invisible control?
#1155
Author: Ted Byers
Date: Fri, 19 Mar 2004 15:32
17 lines
1667 bytes
Here is what I need (and could do almost blindfolded in Borland's C++
Builder).

I need a component that could hold a bitmap, and which can have a size set
independantly of the size of the bitmap, and which can have a size, measured
in pixels, even if it doesn't have bitmap data and so would be invisible.
And this component ought to respond to all mouse events and have its own
cursor.  Is there such a component in swing?  I ask because this is an easy
way to create "hot spots" over top of another control that has a large image
(but without the aggravation of figuring out the exact top, bottom, left and
right edges of the desired hotspot and then calculating whether or not the
mouse is presently over the hotspot - I would instead be able to just
visually place and size the control).

Thanks,

Ted
Re: Can I make an invisible control?
#1156
Author: Gillmer J. Derge (TeamB)
Date: Fri, 19 Mar 2004 15:39
34 lines
1892 bytes
Ted Byers wrote:
> Here is what I need (and could do almost blindfolded in Borland's C++
> Builder).

Other than the part where you mention a cursor, it sounds like you just 
want a JLabel.

> I need a component that could hold a bitmap, 

label.setIcon(bitmap); // not a Windows .BMP

> and which can have a size set
> independantly of the size of the bitmap, 

label.setPreferredSize(size);
label.setMinimumSize(size); // may also be necessary
label.setMaximumSize(size); // may also be necessary

 > even if it doesn't have bitmap data and so would be invisible

label.setIcon(null);
label.setText(""); // null might work too but probably not
label.setOpaque(false);

> And this component ought to respond to all mouse events 

label.addMouseListener(mouseListener);

> and have its own cursor.  

Huh?  Is this supposed to be a text editing component?

-- 
Gillmer J. Derge (TeamB)
Re: Can I make an invisible control?
#1157
Author: Ted Byers
Date: Fri, 19 Mar 2004 16:23
23 lines
1782 bytes
Thanks Gilmer,


"Gillmer J. Derge (TeamB)" <spam@gillmerderge.com> wrote in message
news:405b1413$1@newsgroups.borland.com...
> Ted Byers wrote:
> [snip]
> > and have its own cursor.
>
> Huh?  Is this supposed to be a text editing component?
>
No.  The change in the cursor is just to let the user know that there is
something under the cursor (or perhaps I should have said mouse pointer)
which can respond to a mouse event.  That is, if I create an instance of
this over a cat that is on an image containing several animals, then the
mouse pointer changes to, say, a hand, indicating that something related to
the cat will happen if the user clicks at that position.  And, of course,
when the cursor or mouse pointer is the default shape, the applet won't
respond to any mouse event.

Thanks,

Ted
Re: Can I make an invisible control?
#1158
Author: Gillmer J. Derge (TeamB)
Date: Fri, 19 Mar 2004 16:27
14 lines
1603 bytes
Ted Byers wrote:
> No.  The change in the cursor is just to let the user know that there is
> something under the cursor (or perhaps I should have said mouse pointer)
> which can respond to a mouse event.  

I get it now.  You could also do that with a JLabel.

   label.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

One limitation is that the area obviously needs to be rectangular if 
it's a JLabel, and I haven't seen many rectangular cats. :-)

-- 
Gillmer J. Derge (TeamB)
Re: Can I make an invisible control?
#1159
Author: Ted Byers
Date: Fri, 19 Mar 2004 16:47
24 lines
1972 bytes
"Gillmer J. Derge (TeamB)" <spam@gillmerderge.com> wrote in message
news:405b1f78$1@newsgroups.borland.com...
> Ted Byers wrote:
> > No.  The change in the cursor is just to let the user know that there is
> > something under the cursor (or perhaps I should have said mouse pointer)
> > which can respond to a mouse event.
>
> I get it now.  You could also do that with a JLabel.
>
>    label.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
>
> One limitation is that the area obviously needs to be rectangular if
> it's a JLabel, and I haven't seen many rectangular cats. :-)
>
Thanks.  In this context, it doesn't matter much if the selection area is a
bit larger than the item itself.

But here is another question about the use of JLabel within the designer.
Is it possible to get it to load an image at design time?  Without that
capability, it is rather hard to visually place my invisible JLabels.

Thanks,

Ted
Re: Can I make an invisible control?
#1160
Author: Gillmer J. Derge (TeamB)
Date: Fri, 19 Mar 2004 17:07
32 lines
2366 bytes
Ted Byers wrote:
> But here is another question about the use of JLabel within the designer.
> Is it possible to get it to load an image at design time?  Without that
> capability, it is rather hard to visually place my invisible JLabels.

The easiest way is to include the image file in your project.  It needs 
to be an explicit node in the project, not automatically discovered as 
part of the source tree.  For example,

1. Project | Add Files / Packages / Classes...
2. Browse to the file

Now you should be able to select that image in the designer as the value 
of the label's "icon" property.

If you don't want to clutter up the project with a lot of image files 
just for the sake of the designer, you can put them in a folder within 
the project.  For example,

1. Project | New Folder...
2. Name: images
3. Add the image files as nodes within the folder

The designer also picks up any ImageIcon's (probably any Icon) that's a 
member of your class.  For example, if I add this to my class, I can 
pick "icon1" as the value of a label's "icon" property.

   private ImageIcon icon1 = new 
ImageIcon(Untitled4.class.getResource("boot.gif"));

-- 
Gillmer J. Derge (TeamB)
Re: Can I make an invisible control?
#1162
Author: Ted Byers
Date: Fri, 19 Mar 2004 20:23
37 lines
2811 bytes
"Gillmer J. Derge (TeamB)" <spam@gillmerderge.com> wrote in message
news:405b28d5$3@newsgroups.borland.com...
> Ted Byers wrote:
> > But here is another question about the use of JLabel within the
designer.
> > Is it possible to get it to load an image at design time?  Without that
> > capability, it is rather hard to visually place my invisible JLabels.
>
> The easiest way is to include the image file in your project.  It needs
> to be an explicit node in the project, not automatically discovered as
> part of the source tree.  For example,
>
> 1. Project | Add Files / Packages / Classes...
> 2. Browse to the file
>
> Now you should be able to select that image in the designer as the value
> of the label's "icon" property.
>
OK, I am part way there.  I added a jpeg and a couple gifs to the project
directory, and added them to the project.  They now appear in the drop down
list for icon.  However, that field won't let me type anything, and nothing
happens when I select one of the graphics files.  And nothing appears in the
source listing referring to the image I selected.  When I right click the
file name in the project window, I see an item "New" which brings  up a
submenu containing class, interface, and file.  And JLabel's setIcon
function won't take a file name as an argument.  And when I try
"jLabel1.setIcon(createImageIcon("daynite.gif","a pretty picture"));",
JBuilder tells me it can't resolve createImageIcon().  I must be missing a
key step.

Any ideas on why it adds the file names to the drop down menu for the JLabel
and yet does not actually allow any of my image files to be added to it?

Cheers

Ted
Re: Can I make an invisible control?
#1169
Author: pnichols
Date: Sat, 20 Mar 2004 08:30
58 lines
2944 bytes
Ted Byers wrote:

> 
> "Gillmer J. Derge (TeamB)" <spam@gillmerderge.com> wrote in message
> news:405b28d5$3@newsgroups.borland.com...
>> Ted Byers wrote:
>> > But here is another question about the use of JLabel within the
> designer.
>> > Is it possible to get it to load an image at design time?  Without that
>> > capability, it is rather hard to visually place my invisible JLabels.
>>
>> The easiest way is to include the image file in your project.  It needs
>> to be an explicit node in the project, not automatically discovered as
>> part of the source tree.  For example,
>>
>> 1. Project | Add Files / Packages / Classes...
>> 2. Browse to the file
>>
Short way around this:

(1) Put the images in your /src directory of your project. You can make an
images folder if you wish.
  for Instance:
     /jbprojects
        /myproject
           /src/
             /com
              /yourcompany
                  /images
                    image files
                  /imageclass
                    ImageDisplay.java

 Now in your jbCode do the following
        
 public class ImageDisplay extends JFrame {
   JLabel imageLabel= new JLabel();
   ImageIcon imgForLabel;

   public ImageDisplay() {
   }

  public void jbInit() throws Exception {
    imgforLabel= new
ImageIcon(this.getClass().getResource("../images/TheImage.jpg"));
   //other code

 }

}

Now switch to the designer. You should see the imgForLabel listed for
setIcon. If you don't compile, and retry to set the Icon for the Label. It
should be there now (it will copy the images file to the classes folder on
compile).


     
Re: Can I make an invisible control?
#1171
Author: Ted Byers
Date: Sat, 20 Mar 2004 13:47
16 lines
1704 bytes
Hi Paul,

This helps make some progress.  The image now shows up at design time,
without recompiling, as you said it would.

There is, however, a problem in that the image does not show up at run time.
From within JBuilder, all I see is a square box where the image ought to be,
and from within MW IE (started by double clicking the html file for the
applet) I see a gray square the size the applet ought to be with a little
red 'X' in the top left corner.

Any ideas on why I can now see it at design time and not at run time?

Thanks again,

Ted
Re: Can I make an invisible control?
#1172
Author: Gillmer J. Derge (TeamB)
Date: Sat, 20 Mar 2004 14:52
20 lines
2328 bytes
Ted Byers wrote:
> There is, however, a problem in that the image does not show up at run time.
> From within JBuilder, all I see is a square box where the image ought to be,
> and from within MW IE (started by double clicking the html file for the
> applet) I see a gray square the size the applet ought to be with a little
> red 'X' in the top left corner.

Try getting rid of the ".." in the path in Paul's example.  That is, 
either change it to a full path ("/com/yourcompany/images/TheImage.jpg") 
or move the images directory so it's a subdirectory of the class's 
package and change the path appropriately ("images/TheImage.jpg").  I'm 
not sure if the ".." won't work, but it looked strange to me when I saw it.

Also, make sure the image file actually made it into your project's 
classes directory and/or the JAR file.  I don't see why it wouldn't, but 
it's worth checking, because that would definitely cause this problem if 
it happened.

-- 
Gillmer J. Derge (TeamB)
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads