Advertisement

07.08.2008 at 04:59AM PDT, ID: 23546248
[x]
Attachment Details

resizing a JPanel inside a CardLayout inside a BorderLayout to the size of the Layout pane

Asked by bored_shiva in Java Programming Language, Java AWT & Swing, New to Java Programming

Tags: JAVA

I have the code below. When I add "card1" (JPanel)  into "mainPanel" (JPanel(CardLayout), and then add mainPanel into my DBsetup's JPanel(BorderLayout) CENTER, the sizes don't match up. That is to say that the text doesn't display inside the pane borders, but rather looks as if either card1 or mainPanel are bigger than the CENTER pane. (I'm not sure if I'm explaining this clearly)

My question is: How do I make them all fit one-inside-the-other. How do I get the size of the borderlayout's CENTER pane (which may grow or shrink) and pass it on to the mainPanel and from there to the card JPanel, so they can all resize dynamically.

Please post as much code as you can! I am a complete noobie in Swing, and have a very hard time relating code pieces to where and how they should go in the text.

Thanks.Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
public class DBsetup extends JPanel implements  ActionListener{
public DBsetup(){
		super();
		setLayout(new BorderLayout());
                setSize(500,500);
		next.addActionListener(this);
                next.setSize(20,20);
		previous.addActionListener(this);
                previous.setSize(20, 20);
                previous.setEnabled(false);
		cancel.addActionListener(this);
                cancel.setSize(20, 20);
		
                JPanel buttonPanel = new JPanel();
                buttonPanel.add(previous);
		buttonPanel.add(cancel);                
                buttonPanel.add(next);
		add(buttonPanel, BorderLayout.SOUTH);        
                
                JPanel mainPanel = new JPanel(new CardLayout());
                mainPanel.add(card1(),"card1");
                add(mainPanel,BorderLayout.CENTER);
      
		}
 
	public void actionPerformed(ActionEvent e){}
	
	private JPanel card1(){
		JPanel card = new JPanel();
		//card.setSize(240,120);
		JTextArea welcomeText = new JTextArea("Welcome to the Noteworthy setup wizard! \n\n This wizard will walk you through the " +
				"steps of setting up a new database for your notes, selecting the fields you would like, and running Noteworthy" +
				"for the first time. \n\n\n To preceed press \"Next\", to cancel the setup and exit the program press \"Cancel\" ");
		card.add(welcomeText);
		return card;
		
	}
}
[+][-]07.08.2008 at 05:10AM PDT, ID: 21952924

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Java Programming Language, Java AWT & Swing, New to Java Programming
Tags: JAVA
Sign Up Now!
Solution Provided By: Bart_Cr
Participating Experts: 1
Solution Grade: B
 
 
[+][-]07.08.2008 at 07:42AM PDT, ID: 21954276

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.08.2008 at 10:31PM PDT, ID: 21960810

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628