1

JAppletの作成2つのテキストフィールド、ボタン、およびテキスト領域があります。

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);

問題は、デバッグしてページに配置するときに、アプレットのサイズに応じてコンポーネント/パネルのサイズが変更されることです。これは欲しくない。テキストフィールドを特定のサイズにし、テキスト領域を特定のサイズにします。サイズを設定するためにそこに何かを入れましたが、機能していません。コンポーネントまたはJPanelのいずれかに厳密なサイズを実際に設定するにはどうすればよいですか。

4

1 に答える 1

2

最初のレイアウトの罪は、ユーザーのサイズ変更を無視することです。

ただし、レイアウトマネージャーを使用しなくても、必要なことを実現できます。

private JPanel addressEntryPanel = new JPanel();

addressEntryPanel .setLayout(null);
于 2010-04-19T19:41:00.763 に答える