Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

align text center in JTable.  RSS feed

 
Wael Atef
Greenhorn
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.
 
indian greenhorn
Greenhorn
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.
regards
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!