views:

126

answers:

1

Creating a JApplet I have 2 Text Fields, a button and a Text Area.

private JPanel addressEntryPanel = new JPanel(new GridLayout(1,3));
private JPanel outputPanel = new JPanel(new GridLayout(1,1));
private JTextField serverTf = new JTextField("");
private JTextField pageTf = new JTextField("");
private JTextArea outputTa = new JTextArea();
private JButton connectBt = new JButton("Connect");
private JScrollPane outputSp = new JScrollPane(outputTa);


public void init() 
{
    setSize(500,500);
    setLayout(new GridLayout(3,1));
    add(addressEntryPanel);
    addressEntryPanel.add(serverTf);
    addressEntryPanel.add(pageTf);
    addressEntryPanel.add(connectBt);
    addressEntryPanel.setPreferredSize(new Dimension(50,50));
    addressEntryPanel.setMaximumSize(addressEntryPanel.getPreferredSize());
    addressEntryPanel.setMinimumSize(addressEntryPanel.getPreferredSize());
    add(outputPanel);

    outputPanel.add(outputSp);
    outputTa.setLineWrap(true);
    connectBt.addActionListener(this);

The problem is when debugging and putting it in a page the components / panels resize depending on the applet size. I don't want this. I want the textfields to be a certain size, and the text area to be a certain size. I've put stuff in there to set the size of them but they aren't working. How do I go about actually setting a strict size for either the components or the JPanel.

+1  A: 

The first layout sin is to ignore a user-resize.

However, what you want can be achieved by using no layout manager.That is

private JPanel addressEntryPanel = new JPanel();

addressEntryPanel .setLayout(null);
ring bearer
Yeah I guess it's a part of GridLayout, I don't want to ignore, but with an applet it's going to be in a set width and height but the components looks ugly and stretch to the given size.
Doug