• 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

Dynamically changing contents of a scrollpane, doesn't display?

 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All,

I've run into something of a problem.

I've got a GUI using the BorderLayout, with the top part showing several buttons, the bottom also showing several buttons, and the center section with a JScrollPane which starts out empty but will be updated depending on other things that are going on.

Here's the relevant code:



However, all I get in the middle section is a blank area.

If I delete the last two lines of code, and change the 5th line to read as follows:


then everything works. However, this isn't suitable for my needs.

What am I doing wrong? Why can't I add a table to the JScrollPane after the display has already been set up and shown?

Thanks in advance.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
don't use
scrollPane.add(table);

use
scrollPane.setViewportView(table)
instead, which is same as
scrollPane.getViewport().add(table)

u can add things to JScrollPane, but it's its viewport that's displayed.

//-----------
import javax.swing.*;
public class AdminTab //extends JPanel //implements ActionListener
{

public static void main(String[] args) {
JScrollPane scrollPane = new JScrollPane();
JFrame frame = new JFrame();
frame.add(scrollPane);

*OK scrollPane.setViewportView(new JLabel("haha"));
*NO scrollPane.add(new JLabel("haha"));

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 300);
frame.setVisible(true);
}
}
//-----------------------
 
Joe Vahabzadeh
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks!
 
reply
    Bookmark Topic Watch Topic
  • New Topic