*
The moose likes Swing / AWT / SWT and the fly likes How to add image and text in the same column of table in swings Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply locked New topic
Author

How to add image and text in the same column of table in swings

Rite Sara
Ranch Hand

Joined: Feb 13, 2010
Posts: 56
Hi,

I am able to add image to the column using following code :

DefaultTableModel model = new DefaultTableModel(data, columnNames);
JTable table = new JTable( model )
{
// Returning the Class of each column will allow different
// renderers to be used based on Class
public Class getColumnClass(int column)
{
return getValueAt(0, column).getClass();
}
};

But as per my requirement I need to add some text after the image in the same column ..

I tried using label along with image:

label1 = new JLabel(messg ,icon, JLabel.CENTER);
model.addRow(new Object[]{fieldName , label1});

But in this case it's not taking the image and showing some source code instead of it ...
Please let me know how I can append some text to an image in the same column ..



Thanks,


Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19723
    
  20

Please UseOneThreadPerQuestion. Let's stick to your existing thread, shall we?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to add image and text in the same column of table in swings