dshrenik
asked on
Center align a JLabel
I am using a JLabel andassigning it an Icon. Please let me know how I can center it within a JTable cell.
Thanks!
Thanks!
by default icon is aligned center in the label!
example aligning image and text on the label;
http://download.oracle.com/javase/tutorial/uiswing/components/label.html
ASKER
I dont have any text. I'm doing this:
JLabel label = new JLabel();
label.setIcon(icon);
JLabel label = new JLabel();
label.setIcon(icon);
ASKER
Im doing that inside the method "getTableCellRendererCompo nent()" in a class that extends DefaultTableCellRenderer
Then should not be any problem
ASKER
But, It is being left aligned!
the DefaultTableCellRenderer is itself a JLable, you don't have to create one, just calling setIcon( icon ) would do!
check your image size and and display area!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I had to do
label.setHorizontalAlignme nt(SwingCo nstants.CE NTER);
Thanks!
label.setHorizontalAlignme
Thanks!