This week's book giveaway is in the HTML/CSS/JavaScript forum.
We're giving away four copies of Practical SVG and have Chris Coyier on-line!
See this thread for details.
Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Help with jscrollpane and jtable

 
sat rad
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have a table which i want to put in a jscrollpane, below is my code snippet. By this way nothing shows up in the scroll pane. If I just add the table to the tempPanel, like
tempPanel.add(colorTable, BorderLayout.SOUTH);
values are there. Could anyone please let me know why this could happen. Any help is greatly appreciated.

colorTable = new JTable(screenColorModel);
colorTable.setShowGrid(false);
colorTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
colorTable.setBackground(getBackground());
colorTable.setDefaultRenderer(Object[].class, new ScreenColorRenderer());
colorTable.setRowSelectionAllowed(false);
colorTable.setColumnSelectionAllowed(false);
colorTable.setCellSelectionEnabled(false);
colorTable.getColumnModel().getColumn(0).setMaxWidth(30);
colorScroll = new JScrollPane(colorTable);

tempPanel = new JPanel(new BorderLayout());
tempPanel.add(colorScroll, BorderLayout.SOUTH);

Thanks
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JScrollPane will size to fit the table. If the table has only colors, ie, no text, then its preferredSize.height may be very small. The south section of the BorderLayout will show the scrollPane at its preferredSize, which, matching the child table, could be very small.
Possible solutions to investigate/explore:
set the row height for the table
set a preferredSize for the table
set a preferredSize for the scrollPane
set the preferredScrollableViewportSize for the table.
 
satya sahu
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If i have understood your problem correctly then may be you can try like this :
jScrollpane.getViewPort().add(table);
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!