• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

JTable and JButton question

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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,
 
Ramses Butarbutar
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 3244
30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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..
 
a fool thinks himself to be wise, but a wise man knows himself to be a fool - shakespeare. foolish tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic