即时消息与我的代码有一点问题。我创建了一个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)(最小完备测试和可读实施例)。 –