Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

align text center in JTable.

Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
i want to align the text centei JTable cells how can i perform that.
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To achieve what you are looking for, use cell renderer for your table. Use the interface TableCellRenderer.
In the interface you have a method "getTableCellRendererComponent" method which has various parameters. This renderer extends JLabel. You have to pass your cell to this renderer and it will be converted to JLabel. Use the SwingConstants.setHorizontalAlignment(CENTER) to display your text at the center of the cell.
Hope you are able to follow the flow.
Are we home yet? Wait, did we forget the tiny ad?
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic