2012-01-18 23 views
3

JFrameにJTextFieldとJTextAreaがあります。ただし、アプリケーションを実行すると、ウィンドウを最小化するとJTextFieldのサイズが変更されます。通常は倍になるか、高さが3倍になりますが、毎回どのようにサイズが変更されるかは一貫していません。なぜこれが起こっているのか分かりません。私は実際に直接的な解決策を求めているわけではなく、問題の原因となっている可能性のあるものがいくつかあります。もしあなたが私をここで助けてくれたら、それはすばらしくなるでしょう。おかげ最小化するとJTextFieldのサイズが変更される

は編集:ここで私はそれを初期化するために使用しているコードです。

public class Console extends JPanel implements ActionListener, Serializable { 
    boolean ready = false; 
    protected JTextField textField; 
    protected JTextArea textArea; 
    private final static String newline = "\n"; 
    Game m_game; 
    Thread t; 

public Console(Game game) { 
    super(new GridBagLayout()); 

    m_game = game; 
    textField = new JTextField(20); 
    textField.setPreferredSize(null); 
    textField.addActionListener(this); 

    textArea = new JTextArea(20, 60); 
    textArea.setEditable(false); 
    textArea.setWrapStyleWord(true); 
    textArea.setLineWrap(true); 
    Font comic = new Font("Serif", Font.PLAIN, 14); 
    textArea.setFont(comic); 
    JScrollPane scrollPane = new JScrollPane(textArea); 

    //Add Components to this panel. 
    GridBagConstraints c = new GridBagConstraints(); 
    c.gridwidth = GridBagConstraints.REMAINDER; 

    c.fill = GridBagConstraints.HORIZONTAL; 
    c.fill = GridBagConstraints.BOTH; 
    c.weightx = 1.0; 
    c.weighty = 1.0; 
    add(scrollPane, c); 
    add(textField, c); 
} 

public void actionPerformed(ActionEvent evt) { 
    String text = textField.getText(); 
    m_game.input = text; 
    textField.selectAll(); 
    textArea.setCaretPosition(textArea.getDocument().getLength()); 
    m_game.wait = false; 
    synchronized (m_game){ 
     ready = true; 
     m_game.notifyAll(); 
    } 
} 

public void createAndShowGUI() { 
    //Create and set up the window. 
    JFrame frame = new JFrame("Game"); 
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 

    //Add contents to the window. 
    frame.add(new Console(m_game)); 

    //Display the window. 
    frame.pack(); 
    frame.setVisible(true); 
} 
+0

コードワイズは何をしていますか? –

+0

レイアウトでやっていることかもしれません。 – fireshadow52

+1

すぐに役立つように、[SSCCE](http://sscce.org/)を投稿してください。 –

答えて

関連する問題