• 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
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

How to gray out one particular row in JTable

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,Can anyone help with the following questions?
1)How can I grayout a row in JTable? I am using my own table model extends AbstractTableModel.
2)How can I use different render in the same column? Say if I use default render, I tried to set the table data data[1][1]=String and data[1][2]=boolean value, this will cause exception because the getColumnClass method assume all cells in a column have the same object type.
3) How can make the horizontal scroll appear? I am using JScrollPane for a JTable,
JScrollPane tableScroller = new JScrollPane(table)
I only see the vertical scroll bar not the horizontal one. I would like to also see the horizontal scroll when I adjust the table column size for some rows that have very long text(could out of the JScrollPane size.
Thank you!
 
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1) In JTable you only deal with columns. You have to write your own TableCellrenderer Class extending JLabel, implementing TableCellTenderer and set that for every Column of JTable.
In the method getTableCellRendererComponent(), set colors for the component (internally JLabel).
2) Let getValueAt() method return the Data Type by returning an Object of its Wraper Class
3) By Default, You won't get HorizantalScrollBars. You have to call setAutoResizeMode(AUTO_RESIZE_OFF) on JTable after setting data to its TableModel.
 
What? What, what, what? What what tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic