Link to home
Start Free TrialLog in
Avatar of dshrenik
dshrenikFlag for United States of America

asked on

Swing: JTable with JLabel and images

Please let me know how I can create a JTable with JLabels and images.

I want a 4X3 table with jlabels in the first 2 columns and images in the third column.

If possible, please provide some sample code.

Thanks!
Avatar of for_yan
for_yan
Flag of United States of America image


You need to use TableCellRendereere
This is an example:
http://www.java2s.com/Code/Java/Swing-JFC/TableRendererSample.htm
Avatar of dshrenik

ASKER

I am not sure how I can use JLabels and images inside a table. If possible, can you provide some sample code? Thanks!
Table cell renderer retrns Component in this method:

 public Component getTableCellRendererComponent(JTable table, Object value,
      boolean isSelected, boolean hasFocus, int row, int column) {

you should define this method so that you'll check row and column and either
return smple Lavble for some columns or return say JPanel
showing the image depeneding on the value of parameter column
ASKER CERTIFIED SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial