Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable in a JScrollPane (last column heading of table always cut)

 
mark I thomas
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JTable inside a JScrollPane. I found that, regardless of the number of columns, the last column heading of the table is always one pixel cut from the right end. Even I reduce the number of columns it does not help. All other columns look fine in width

How can I solve this problem ?

*****************************************
JTable table = new JTable(new MyTableModel());
table.setPreferredScrollableViewportSize(new Dimension(1300, 500));
table.setAutoResizeMode( JTable.AUTO_RESIZE_OFF );
table.getColumnModel().getColumn(1).setPreferredWidth(100);
table.getColumnModel().getColumn(2).setPreferredWidth(100);
table.getColumnModel().getColumn(3).setPreferredWidth(100);
table.getColumnModel().getColumn(4).setPreferredWidth(100);
table.getColumnModel().getColumn(5).setPreferredWidth(100);
....

JScrollPane scrollPane = new JScrollPane();
scrollPane.setViewportView(table);
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
...

******************************************
 
Rob Camick
Ranch Hand
Posts: 2539
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see a problem using JDK6_7 on XP.

If you need more help post your SSCCE demonstrating the problem.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic