为什么我不能在 JTextArea 中键入,除非我调整 window 的大小?
Why can't I type in a JTextArea unless I resize the window?
我在 JFrame 中放置了一个 JTextArea,但遇到一个问题,即我只能在我的 JTextArea 中键入内容,除非我调整 window 的大小。如何让 JTextArea 让我在 window 运行时立即输入而无需调整它的大小?
public class Frame extends JFrame{
public Note() {
this.setSize(new Dimension(1000, 1000));
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public JScrollPane createContent(){
JTextArea textArea = new JTextArea();
JScrollPane scrollPane = new JScrollPane(textArea);
this.add(scrollPane, BorderLayout.CENTER);
return null;
}
public static void main(String[] args) {
new Note();
Note mainWindow = new Note();
}
}
public class 注意扩展 JFrame{
private static final long serialVersionUID = 1L;
public Note() {
createContent(); // add this line into your code.
int x = 400;
int y = 300;
this.setSize(new Dimension(x, y));
this.setTitle("Post-It Note");
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public JScrollPane createContent(){
Color textAreaColor = new Color(248, 247, 235);
JTextArea textArea = new JTextArea();
JScrollPane scrollPane = new JScrollPane(textArea);
scrollPane.setBorder(null);
textArea.setBackground(textAreaColor);
scrollPane.setBackground(textAreaColor);
textArea.setMargin(new Insets(10, 15, 20, 20));
this.add(scrollPane, BorderLayout.CENTER);
return null;
}
public static void main(String[] args) {
new Note();
// mainWindow.createContent(); comment this line...
}
}
注:
进入您的旧代码,
new Note(); // this one create 1-frame..
...
// Note mainWindow = new Note(); this one also create another frame so need to comment it
// mainWindow.createContent(); does not required because already this method called by constructor...
我在 JFrame 中放置了一个 JTextArea,但遇到一个问题,即我只能在我的 JTextArea 中键入内容,除非我调整 window 的大小。如何让 JTextArea 让我在 window 运行时立即输入而无需调整它的大小?
public class Frame extends JFrame{
public Note() {
this.setSize(new Dimension(1000, 1000));
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public JScrollPane createContent(){
JTextArea textArea = new JTextArea();
JScrollPane scrollPane = new JScrollPane(textArea);
this.add(scrollPane, BorderLayout.CENTER);
return null;
}
public static void main(String[] args) {
new Note();
Note mainWindow = new Note();
}
}
public class 注意扩展 JFrame{
private static final long serialVersionUID = 1L;
public Note() {
createContent(); // add this line into your code.
int x = 400;
int y = 300;
this.setSize(new Dimension(x, y));
this.setTitle("Post-It Note");
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public JScrollPane createContent(){
Color textAreaColor = new Color(248, 247, 235);
JTextArea textArea = new JTextArea();
JScrollPane scrollPane = new JScrollPane(textArea);
scrollPane.setBorder(null);
textArea.setBackground(textAreaColor);
scrollPane.setBackground(textAreaColor);
textArea.setMargin(new Insets(10, 15, 20, 20));
this.add(scrollPane, BorderLayout.CENTER);
return null;
}
public static void main(String[] args) {
new Note();
// mainWindow.createContent(); comment this line...
}
}
注:
进入您的旧代码,
new Note(); // this one create 1-frame..
...
// Note mainWindow = new Note(); this one also create another frame so need to comment it
// mainWindow.createContent(); does not required because already this method called by constructor...