Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Swing / AWT / SWT
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
paul wheaton
Ron McLeod
Jeanne Boyarsky
Sheriffs:
Paul Clapham
Saloon Keepers:
Tim Holloway
Roland Mueller
Bartenders:
Forum:
Swing / AWT / SWT
JTable
Prashanth Bhanu
Ranch Hand
Posts: 110
posted 20 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi Friends,
I want to put an image in one of the column of the JTable and one image in only on the first cell of the JTable.How to proceed with this???.
Thanks in adavnce
Prashanth
Don Kiddick
Ranch Hand
Posts: 580
posted 20 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Where are you stuck ?
Michael Dunn
Ranch Hand
Posts: 4632
posted 20 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.table.*; class Testing extends JFrame { public Testing() { setLocation(400,100); setDefaultCloseOperation(EXIT_ON_CLOSE); MyDTCR renderer = new MyDTCR(); String colNames[] = {"Name", "Age"}; Object[][] data = {{"joe","21"},{"fred","31"},{"mary","18"}}; DefaultTableModel dtm = new DefaultTableModel(data,colNames); JTable table = new JTable(dtm); TableColumn tc = table.getColumnModel().getColumn(0); tc.setCellRenderer(renderer); JScrollPane sp = new JScrollPane(table); sp.setPreferredSize(new Dimension(300,100)); getContentPane().add(sp); pack(); } public static void main (String[] args){new Testing().setVisible(true);} } class MyDTCR extends DefaultTableCellRenderer { public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { JLabel lbl = ((JLabel)super.getTableCellRendererComponent(table,value,isSelected,hasFocus,row,column)); if(row == 0) lbl = new JLabel(new ImageIcon("Test.gif")); else lbl.setIcon(null); return lbl; } }
Hey, I'm supposed to be the guide! Wait up! No fair! You have the tiny ad!
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
JTable
JTable
JTable help
Images in a JTable
Ordering jtable
More...