943,892 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 1071
  • Java RSS
Nov 13th, 2007
0

problem with jpanels

Expand Post »
when ı add two panels into a frame last panel i added seen on the screeen how can i show both panels in one frame
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
enes is offline Offline
9 posts
since Oct 2007
Nov 13th, 2007
0

Re: problem with jpanels

There gone be something wrong with your code. Can you please post it?

PS: Use code tags, press hash "#" sign on post toolbar and paste your code between the tags which will appear
Last edited by peter_budo; Nov 13th, 2007 at 8:32 am.
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 873
Code tags enforcer
peter_budo is offline Offline
6,656 posts
since Dec 2004
Nov 13th, 2007
0

Re: problem with jpanels

It's probobly a layout issue. Try to use something like this

Java Syntax (Toggle Plain Text)
  1.  
  2. class MyFrame extends JFrame
  3. {
  4.  
  5. public MyFrame()
  6. {
  7.  
  8. setSize(800,600);
  9. setTitle("MyFrame");
  10.  
  11. JPanel panel1 = new JPanel();
  12. JPanel panel2 = new JPanel();
  13.  
  14. Container cp = getContentPane();
  15.  
  16. [B][COLOR="Red"] cp.setLayout(new FlowLayout());[/COLOR][/B]
  17.  
  18. cp.add(panel1);
  19. cp.add(panel2);
  20.  
  21. }
  22.  
  23.  
  24. }
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Artmann is offline Offline
19 posts
since Nov 2007
Nov 13th, 2007
0

Re: problem with jpanels

and what makes you think you get only one panel to show if you do that?
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Nov 14th, 2007
0

Re: problem with jpanels

My Example will show two panels.
I just wanted to show him how to add a layout to the frame.
If he hasn't done that he will only see one panel.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Artmann is offline Offline
19 posts
since Nov 2007
Nov 14th, 2007
0

Re: problem with jpanels

Well, the contentPane of the the JFrams already has a layout. It simply needs to be used correctly. If you use add without any anchor parameter then according to the documentation
As a convenience, BorderLayout interprets the absence of a string specification the same as the constant CENTER

So, simply calling add(Component) twice, is the same as calling add(Component, CENTER) twice. She should be calling add(Component, CENTER) and add(Component, SOUTH), for example.

Of course, changing the layout (as your post showed) is always an option, but is not, strictly speaking, needed.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Efficient Connection
Next Thread in Java Forum Timeline: Use different channels to play .wav file





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC