Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Adding JPanels to JScrollPane so that it has a stacking feel

 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
- 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
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 174
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The stacking is okay now.
But that seems to be very unevenly spaced.


screen shot.png
[Thumbnail for screen shot.png]
 
m Korbel
Ranch Hand
Posts: 174
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
whats happens when you move JPanel p = new JPanel(); after code line if (meta.getColumnCount() > 0) {

 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2612
9
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic