
I have problem with creating border for an icon in JLabel. I have JPanel in which I set it into GridLayout. I added Jlabel on the JPanel. The size of the JLabel were according to the size of the icon. However when I tried to set the border on the icon, it created border according to the size of the grid and not the size of the icon inside the grid.
How can I create a border around the image not on the size of the grid?
Why the border followed the size of the grid and not the size of the imageIcon?
JPanel panel= new JPanel(new GridLayout(ROWS,COLS,2,2));
panel.setsize(600,600);
....
JLabel = new JLabel(icon, JLabel.LEFT);
label.setVerticalAlignment(SwingConstants.TOP);
...
label.setborder(BorderFactory.createLineBorder(Color.RED,5));
panel.add(label);
I solved the problem. Thanks to this site http://forums.oracle.com/forums/thread.jspa?messageID=5785467�