即時消息與我的代碼有一點問題。我創建了一個5,1,0,0的網格佈局。我有一個文本框,3個按鈕和一個標籤,其中用戶輸入的結果分析顯示在底部。現在,結果可能會出現在多行中,具體取決於句子中的單詞大小,我的問題是顯示多行結果時,程序的佈局發生變化,我不知道如何保持相同,但只是標籤或Applet窗口本身需要調整大小?Java Applet網格佈局問題
public class assignment_tauqeer_abbasi extends JApplet implements ActionListener {
JTextArea textInput; // User Input.
JLabel wordCountLabel; // To display number of words.
public void init() {
//這從這裏代碼是小程序的定製,這包括背景顏色,文本顏色,文本回地面顏色,標籤和按鈕
setBackground(Color.black);
getContentPane().setBackground(Color.black);
textInput = new JTextArea();
textInput.setBackground(Color.white);
JPanel south = new JPanel();
south.setBackground(Color.darkGray);
south.setLayout(new GridLayout(5,1,0,0));
/* Creating Analyze and Reset buttons */
JButton countButton = new JButton("Analyze");
countButton.addActionListener(this);
south.add(countButton);
JButton resetButton = new JButton("Reset");
resetButton.addActionListener(this);
south.add(resetButton);
JButton fileButton = new JButton("Analyze Text File");
fileButton.addActionListener(this);
south.add(fileButton);
/* Labels telling the user what to do or what the program is outputting */
wordCountLabel = new JLabel(" No. of words:");
wordCountLabel.setBackground(Color.black);
wordCountLabel.setForeground(Color.red);
wordCountLabel.setOpaque(true);
south.add(wordCountLabel);
/* Border for Applet. */
getContentPane().setLayout(new BorderLayout(2,2));
/* Scroll bar for the text area where the user will input the text they wish to analyse. */
JScrollPane scroller = new JScrollPane(textInput);
getContentPane().add(scroller, BorderLayout.CENTER);
getContentPane().add(south, BorderLayout.SOUTH);
} // end init();
public Insets getInsets() {
// Border size around edges.
return new Insets(2,2,2,2);
}
// Applet的定製
的端這是我的佈局代碼。任何幫助將是明智的!
爲了更好地幫助越早,張貼[MCTaRE](http://stackoverflow.com/help/mcve)(最小完備測試和可讀實施例)。 –