[英]ScrollPane doesn't show up until I resize the window
我是一个java新手,我正在开发一个带菜单,scrollpane和textarea的简单应用程序。
到目前为止,我已经在表单上得到了我想要的所有东西,但是当我启动我的应用程序时,滚动窗格/文本区域将不会显示,直到我重新调整窗口。
我尝试使用其他论坛上建议的重绘方法来解决类似问题,但它没有用,也许我没有正确使用它:S
这是我的班级:
public class FenetreEditeur {
public static void main(String[] args){
FenetreEditeur f = new FenetreEditeur();
}
public FenetreEditeur(){
JFrame frame = new JFrame();
frame.setVisible(true);
frame.setSize(400,400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
initMenuBar(frame);
JTextArea areaMain = new JTextArea();
JScrollPane scrollPane = new JScrollPane(areaMain);
frame.add(scrollPane);
}
private void initMenuBar(JFrame frame){
JMenuBar menu = new JMenuBar();
JMenu revision = new JMenu("Revision");
JMenuItem statistiques = new JMenu("Statistiques");
JMenuItem grammaire = new JMenu("Grammaire et orthographe");
JMenuItem analyse = new JMenu("Analyse Automatique");
menu.add(revision);
revision.add(statistiques);
revision.add(grammaire);
revision.add(analyse);
frame.setJMenuBar(menu);
}}
任何帮助/提示将不胜感激。
谢谢!
添加后调用scrollPanel.revalidate()
,或者更好,将frame.setVisible(true)
移动到结尾:
public FenetreEditeur(){
JFrame frame = new JFrame();
frame.setSize(400,400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
initMenuBar(frame);
JTextArea areaMain = new JTextArea();
JScrollPane scrollPane = new JScrollPane(areaMain);
frame.add(scrollPane);
frame.setVisible(true);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.