Sizing error

Okay, so I have this formatting code:

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import java.util.*;

publicclass Gui1{

JTextArea area;

JScrollPane area0;

JTextField field;

JTextField field2;

JPanel panel;

ArrayList good =new ArrayList();

ArrayList bad =new ArrayList();

Gui1 gui;

JPanel contentPanel;

publicstaticvoid main(String[] args){

Gui1 gui =new Gui1();

gui.start(10,gui);

}

publicvoid start(int bg, Gui1 g){

gui = g;

panel =new JPanel();

JPanel panel2 =new JPanel();

panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

panel2.setLayout(new BoxLayout(panel2, BoxLayout.X_AXIS));

field =new JTextField();

field2 =new JTextField();

JButton button =new JButton("Set");

button.addActionListener(new SetterListener());

JButton button2 =new JButton("Ready!");

//button2.addActionListener(new GoListener());

JButton button3 =new JButton("AutoAdd");

button3.addActionListener(new AutoListener());

panel.add(field);

panel.add(field2);

panel.add(panel2);

panel2.add(button);

panel2.add(button3);

panel2.add(button2);

JFrame frame =new JFrame("Diff'rent window select");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

contentPanel =new JPanel();

contentPanel.setBackground(Color.darkGray);

contentPanel.setSize(200,200);

area =new JTextArea(27,43);

area.setText("Game created. \n");

area0 =new JScrollPane(area0);

area.setLineWrap(true);

area0.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

area0.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

JPanel holder =new JPanel();

JPanel holder2 =new JPanel();

JButton areaButton =new JButton("Show TextCode");

areaButton.addActionListener(new AreaShowListener());

JButton panelButton =new JButton("Show Game");

panelButton.addActionListener(new PanelShowListener());

holder2.setLayout(new BoxLayout(holder2, BoxLayout.X_AXIS));

holder2.add(panelButton);

holder2.add(areaButton);

area0.setVisible(false);

area.setVisible(false);

holder.add(contentPanel);

holder.add(area0);

holder.setBackground(Color.green);

frame.setSize(500,500);

frame.getContentPane().add(BorderLayout.CENTER, holder);

frame.getContentPane().add(BorderLayout.NORTH, holder2);

frame.getContentPane().add(BorderLayout.SOUTH, panel);

frame.setVisible(true);

//for(int y=1; y<=bg; y++){

//bad.add(new Badguy(0,y));

//}

field.requestFocus();

}

//public void go(Gui1 g){

//panel.setVisible(false);

//while((!good.isEmpty()) && (!bad.isEmpty())){

//for(int i=0; i<g.good.size(); i++){

//if(!bad.isEmpty()){

//Melee h = (Melee)(good.get(i));

//int en = h.check(g);

//h.walk(en,g);

//}

//}

//for(int i=0; i><g.bad.size(); i++){

//if(!good.isEmpty()){

//Badguy b = (Badguy)(bad.get(i));

//int en = b.check(g);

//b.walk(en,g);

//}

//}

//}

//if(good.isEmpty()){

//g.area.append("Badguys won! \n");

//for(int i=0;i<bad.size();i++){

//Badguy baddy = (Badguy)(bad.get(i));

//g.area.append("Badguy "+baddy.getId()+" survived. \n");

//}

//}else if(bad.isEmpty()){

//g.area.append("Goodguys won! \n");

//for(int i=0;i<good.size();i++){

//Melee goody = (Melee)(good.get(i));

//g.area.append("Goodguy "+goody.getId()+" survived. \n");

//}

//}

//}

class AreaShowListenerimplements ActionListener{

publicvoid actionPerformed(ActionEvent event){

area0.setVisible(true);

area.setVisible(true);

contentPanel.setVisible(false);

}

}

class PanelShowListenerimplements ActionListener{

publicvoid actionPerformed(ActionEvent event){

area0.setVisible(false);

area.setVisible(false);

contentPanel.setVisible(true);

}

}

class SetterListenerimplements ActionListener{

publicvoid actionPerformed(ActionEvent event){

int x = Integer.parseInt(field.getText());

int y = Integer.parseInt(field2.getText());

//good.add(new Melee(x,y));

area.append("New goodguy at ("+x+"x"+y+"). \n");

field.setText("");

field2.setText("");

field.requestFocus();

}

}

//class GoListener implements ActionListener {

//public void actionPerformed(ActionEvent event){

//gui.go(gui);

//}

//}

class AutoListenerimplements ActionListener{

publicvoid actionPerformed(ActionEvent event){

for(int i=0;i<10;i++){

//good.add(new Melee(1,i));

area.append("New goodguy at (1x"+i+"). \n");

}

field.setText("");

field2.setText("");

field.requestFocus();

}

}

}

(That's just formatting, so the //'d stuff doesn't apply,)

But if you compile and run it, the JTextArea is 1 pixel, and the JPanel is very small too. If you remove the JScrollPane from the picture, though, the JTextArea is (about) the right size!

How do I make the size of the JScrollPane and JPanel adhere to the size of the panel they are in? Help!>

[10086 byte] By [KKera] at [2007-11-27 6:46:45]
# 1

hey,

your code is set up a little confusing... but anyways... you made a little mistake in creating the scrollpane...

area0 = new JScrollPane(area0); // i guess you want to add the area and not the scrollpane (area0)

area0 = new JScrollPane(area); // change it and it should be displayed

// on setting the size of the controlpanel use setPrefferedSize with a new Dimension object instead of setSize

contentPanel.setPreferredSize(new Dimension(200,200));

i tried your code and its working with these changes

izziieea at 2007-7-12 18:19:09 > top of Java-index,Desktop,Core GUI APIs...
# 2

Your posting has too much unnecessary code to look at.

We don't want to see you commented out code so get rid of it.

We don't care about your ActionListener code, so get rid of it.

We don't care about the components added to the North and South of the content pane since they are displayed correctly.

Once you get rid of all this unnecessary code, then maybe we will be able to see what you are actually doing and find the problem.

Its called a SSCCE. You need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program[/url] (SSCCE) that demonstrates the incorrect behaviour.

camickra at 2007-7-12 18:19:09 > top of Java-index,Desktop,Core GUI APIs...
# 3
Oh. Wow. Now I feel stupid.Thanks!
KKera at 2007-7-12 18:19:09 > top of Java-index,Desktop,Core GUI APIs...