• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help with jscrollpane and jtable

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If i have understood your problem correctly then may be you can try like this :
jScrollpane.getViewPort().add(table);
 
reply
    Bookmark Topic Watch Topic
  • New Topic