How can I make a Label or Icon clickable?

Hi I have 3 lables which have imageicons in them which keep changing from red to green to blue depending on the status of some server connection, Now I have a get info button right next to it which pops up a dialog box which gives more information about the server connection there like the IP PORT etc, I want to remove this get info button and have the user click the image icons to ger the same information?

I have a JPanel where I have all these compoents and this panel has a titled border, is it possible to make the border title clickable, any of the 2 solutions would be greatly appreciated.

Thanks a ton,

Ankur

[644 byte] By [helpwithjava] at [2007-9-30 21:01:36]
# 1
Clicking on a border is wierd, if you ask me. But as far as clicking on a JLabel goes, use a MouseListener.
jToohey at 2007-7-7 2:33:42 > top of Java-index,Desktop,Core GUI APIs...
# 2
I recommend using a JButton to display your image icon and just toss the JLabel completely. Remember you can create a button using an icon instead of a string with new JButton( icon );and JButton.setIcon().
miteke at 2007-7-7 2:33:42 > top of Java-index,Desktop,Core GUI APIs...
# 3
Further, the JButton can have BOTH text and an image. http://java.sun.com/docs/books/tutorial/uiswing/components/button.html
KelVarnson at 2007-7-7 2:33:42 > top of Java-index,Desktop,Core GUI APIs...
# 4
Thanks, i will try this, so is there a way of making the button such that it doesnt show any borders?
helpwithjava at 2007-7-7 2:33:42 > top of Java-index,Desktop,Core GUI APIs...
# 5
It would be great if there was some sort of Swing component called, say, (J)ClickableRegion.It would basically be a JButton, but would not pop in an out. Or it could be a JLabel with focus. Depends how you look at it...
Lutha at 2007-7-7 2:33:42 > top of Java-index,Desktop,Core GUI APIs...
# 6
> Thanks, i will try this, so is there a way of making the button such that it doesnt show any borders?Read the API for AbstractButton.
jToohey at 2007-7-7 2:33:42 > top of Java-index,Desktop,Core GUI APIs...
# 7

Here's an example of some tweaks for cool-looking toolbar buttons, in Java 1.5.

import java.awt.*;

import java.net.*;

import javax.swing.*;

public class ButtonsExample {

public static void main(String[] args) throws MalformedURLException {

String prefix = "http://java.sun.com/developer/techDocs/hi/repository/graphicsRepository/toolbarButtonGraphics/media/";

String suffix = "24.gif";

String[] urls = {"Play", "Pause", "Stop", "FastForward", "Rewind", "StepBack", "StepForward", "Movie", "Volume"};

UIManager.put("Button.margin", new Insets(0,0,0,0));

JToolBar tb = new JToolBar();

for(int i=0; i<urls.length; ++i) {

JButton btn = new JButton(new ImageIcon(new URL(prefix + urls[i] + suffix)));

btn.setBorderPainted(false);

btn.setFocusPainted(false);

btn.setContentAreaFilled(true);

btn.setOpaque(false);

tb.add(btn);

}

JFrame f = new JFrame("ButtonsExample");

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

f.getContentPane().add(tb, BorderLayout.NORTH);

f.setSize(400,100);

f.setLocationRelativeTo(null);

f.setVisible(true);

}

}

>

jToohey at 2007-7-7 2:33:42 > top of Java-index,Desktop,Core GUI APIs...
# 8
JButton b=new JButton();b.setBoder(null);is it the case?
what.why.how at 2007-7-7 2:33:42 > top of Java-index,Desktop,Core GUI APIs...
# 9
JButton button = new JButton(icon);button.setBorderPainted(false);button.setMargin(new Insets(0,0,0,0);You will see no border at all.
jacklty at 2007-7-7 2:33:42 > top of Java-index,Desktop,Core GUI APIs...