File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Adding JPanels to JScrollPane so that it has a stacking feel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Adding JPanels to JScrollPane so that it has a stacking feel" Watch "Adding JPanels to JScrollPane so that it has a stacking feel" New topic
Author

Adding JPanels to JScrollPane so that it has a stacking feel

Jacky Luk
Ranch Hand

Joined: Aug 02, 2012
Posts: 601
It seems like the last item always overwrites the previous items, so that only one of those is displayed
Also, I have another question is that if I have to have 4 to 5 JPanels stacking up in the JFrame, is it
the only way to break the JFrame up into BorderLayout, and break down the Center Panel again?
Now, I add a JScrollPane into the JFrame with this.add(customerListingPane, BorderLayout.SOUTH);
and BorderLayout.PAGE_END and I can't see the JScrollPane in anyway?
m Korbel
Ranch Hand

Joined: Jun 19, 2012
Posts: 157
- customerListingPane.getViewport().add(displayCustomerPanel); don't add something to JViewport, put only JPanel to JScrollPane and add a new DisplayCustomerPanel to this JPanel

- change JScrollPane.getVerticalScrollBar().setUnitIncrement(int) for natural scrolling, or add/override Scrollable for this JPanel

- invalidate() is propertly implemented in all APIs for standard LayoutManagers, this notifiers == put everything to trash

- never to invalidate JViewport, JViewport isn't container, can cause with interesting side artefacts (really you don't need that)

- you have to call parentPanel.revalidate(), parentPanel.repaint(), once time as last code lins after loop ended, meaning all Objects are removed and new Objects are added

- simple question why not to use JTable instead
Jacky Luk
Ranch Hand

Joined: Aug 02, 2012
Posts: 601

Hi
That doesn't still have the stacking effect, it only shows the last record, but I can see it loops twice.


BTW, can it have the fancy stacking effect if I use JTable
http://www.youtube.com/watch?v=a_3YhX7aELQ
m Korbel
Ranch Hand

Joined: Jun 19, 2012
Posts: 157
JPanel in JScrollPane is prepared Object, e.g. pseudocode






EDIT

Whatever inside JScrollPane can't returns reasonable PreferredSize, then

- override PreferredSize for DisplayCustomerPanel

- parentPanel should be laid by GridLayout (start with this LayoutManager)
Jacky Luk
Ranch Hand

Joined: Aug 02, 2012
Posts: 601
The stacking is okay now.
But that seems to be very unevenly spaced.




[Thumbnail for screen shot.png]

m Korbel
Ranch Hand

Joined: Jun 19, 2012
Posts: 157
whats happens when you move JPanel p = new JPanel(); after code line if (meta.getColumnCount() > 0) {

Jacky Luk
Ranch Hand

Joined: Aug 02, 2012
Posts: 601
m Korbel wrote:whats happens when you move JPanel p = new JPanel(); after code line if (meta.getColumnCount() > 0) {



I am afraid it's the same.
Thanks for continuous assistance
Jack
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2227
    
    8
A GridLayout resizes to take up the space available. You can try something like:





A JTable is probably a better component to display the data.

Jacky Luk
Ranch Hand

Joined: Aug 02, 2012
Posts: 601
Rob Camick wrote:A GridLayout resizes to take up the space available. You can try something like:





A JTable is probably a better component to display the data.



Thanks Rob, that does that nicely.
Jack
Jacky Luk
Ranch Hand

Joined: Aug 02, 2012
Posts: 601
Hello,
When I create a new JPanel , how do I make it selectable and how do I highlight it?
I'd like to see it to respond to mouse clicks.


How do I make access to the parent?
Thanks
Jack
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Adding JPanels to JScrollPane so that it has a stacking feel