aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JTable and JButton question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable and JButton question" Watch "JTable and JButton question" New topic
Author

JTable and JButton question

Ramses Butarbutar
Ranch Hand

Joined: Jun 16, 2009
Posts: 52
Hi all, ,

I made a sample testing class of JTable.. and create each data as object based on columnNames.
And i want to put a button in JTable but it's doesn't work.. only show up text(javax.swing.JButton..).
How can i do this.. put a button into JTable??


Thanks..

Ramses,


At the center of non-violence stands the principle of love
.... Martin Luther King, Jr.
Ramses Butarbutar
Ranch Hand

Joined: Jun 16, 2009
Posts: 52
Hehe.. sorry all, I'm too lazy to think today...
I just remember what i need to display a jbutton in a jtable..
I have to make my own TableCellRenderer, get component which return component as the renderer.. and next step is to make TableModel that implement the return because DefaultTableModel is designed to work with "DefaultTableCellRenderer" that return string...
And final step is creating buttonmouselistener for action..

Thanks guys for your attention..

Ramses
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2200
    
    7
Its more complicated than that. You need a custom renderer and a custom editor.

The Table Button Column entry can help you out.
Ramses Butarbutar
Ranch Hand

Joined: Jun 16, 2009
Posts: 52
Rob Camick wrote:Its more complicated than that. You need a custom renderer and a custom editor.

The Table Button Column entry can help you out.


I've read your clue.. So what you have written in your class is basicly to specify column that is used to contain the button so renderer and editor can perform invoke action based on row number of clicked button...
Hmm... great thought...
What that i want to point in my previous message is to handle what DefaultTableCellRenderer can't handle if return value is component..so we have to customize to get getTableCellRendererComponent() which returns a java.awt.Component that knows how to draw the contents of a specific cell.
To maintain the column is the job of TableCellRenderer, it will return same component for every cell of the column..
I think that the simply way to implement a button in a table..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTable and JButton question