• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

adding components to JPanel

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

I want to know how to make visible components added to a JPanel that happens to be inside a JScrollPane after the JFrame has already been created. My class, that extends JFrame, has the jbInit() method you see below. At the very end of the jbInit() method I set up cardPanel to a GridLayout of 10 rows 1 column. This is so that I can display up to 10 distinct components as I add them dynamically using the displayResults() method. As you can imagine, the new HandStats (which extend JPanel) if they are being added to cardPanel, are not being displayed. I've tried using repaint() methods but they don't do anything. How do I accomplish this? Also, how do I remove the HandStats objects from cardPanel so that I can display another new set of them?

Alan

*************************************************
 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I've got a solution of sorts...

Maybe I've just been at work too long today, I'm not too comfortable with this solution. I got this to work by adjusting the viewPortView() of the scrollPane after I added the extra components.

Here is a complete listing. I hope it helps you out.


Just copy and past it.
 
jefff willis
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I guess I should tell you how to execute it.

Run it, and it will start with a handful of components on a Panel. In the File Menu up top, there is an "Add" option that will add a handful of additional components to that panel.
[ November 02, 2004: Message edited by: jefff willis ]
 
Hey, I'm supposed to be the guide! Wait up! No fair! You have the tiny ad!
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic