• Post Reply Bookmark Topic Watch Topic
  • New Topic

JList not appearring

 
Mike Perkins
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am struggling to get a JList to appear in my JPanel. I can see the panel itself in my JFrame which is being called from another class that extends JFrame so I presume my problem must lie within the GUIClientList class but have little experience so cannot be sure.
Any advice on other aspects of my code would be welcome too.

thanks for looking!

 
Paul Clapham
Sheriff
Posts: 21892
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, your JList doesn't have any entries in it so I'm not sure what you expect to see. But anyway, if you're having trouble finding a component in your Swing GUI one way is to put, say, a red border around the component. Give that a try and see what happens.
 
Paul Clapham
Sheriff
Posts: 21892
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And, welcome to the Ranch!

I edited your post so that your code is inside "code" tags. That makes it much easier for others to read as code. Could you do that in future, please?
 
Mike Perkins
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the edit. Added a border to my jList but no border appears, I guess that's because my JList has nothing in it so zero size. I did expect to see "TEST" in my JList because I added it to my listmodel. I am guessing from your reply that that isn't the case so am looking in that area for errors.
 
Campbell Ritchie
Marshal
Posts: 52590
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome again

How are you adding that panel to your frame?
 
Mike Perkins
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's the code that adds the JPanel to my JFrame.



The panel is pink so I can see that it is being added to my frame. I think I may have layout issues as I have added setBounds(x,y,w,h) to the scrollpane and hey presto my JList now appears
 
Campbell Ritchie
Marshal
Posts: 52590
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't mix setBounds and layouts.
If you are using border layout and have not specified where to add a component, it defaults to “CENTER”. If you have two components there one will hide the other.
 
Darryl Burke
Bartender
Posts: 5155
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:If you are using border layout and have not specified where to add a component, it defaults to “CENTER”. If you have two components there one will hide the other.

More precisely, the layout will manage the bounds of only the last added component and show it at the bottom of the z-order. Any component added earlier and not removed will have its default bounds at [0,0,0,0]; if its bounds are expressly set, it will display on top of the last added component.
 
Mike Perkins
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
haven't done much GUI stuff before so need to get to grips with layout managers. Thanks for looking.
Mike
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!