简体   繁体   English

调整帧大小之前,JTextField上的文本不会出现

[英]Text on JTextField doesn't appear until frame resize

When I click on a button a property frame appears. 当我单击一个按钮时,会出现一个属性框。 Each row has these 3 fields : JLabel name, JTextField value, JSlider slider. 每行具有以下3个字段:JLabel名称,JTextField值,JSlider滑块。 My problem is that when the frame shows, it displays the values correctly, but the text in the JTextField fails to appear until I resize the frame for a bit. 我的问题是,当框架显示时,它会正确显示值,但是JTextField中的文本无法显示,直到我重新调整框架的大小。 I use GridLayout for the JPanel containing the components Any suggestions on what I might do? 我为包含组件的JPanel使用GridLayout关于我可能会做什么的建议?

frame = new JFrame();
    frame.setSize(500, 400);
    frame.setTitle("Properties of " + nume);

    ok = new JButton("OK");
    no = new JButton("Cancel");

    modified = true;

// <"Labels, sliders ,text fields"> // <“标签,滑块,文本字段”>

// <"add the components on the panel"> // <“在面板上添加组件”>

    buttonsPanel.add(ok);
    buttonsPanel.add(no);

    JSplitPane framePanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, jsp, buttonsPanel);
    framePanel.setDividerLocation(0.9);
    framePanel.setDividerSize(0);
    framePanel.setResizeWeight(1);

    frame.add(framePanel);

Here is what my frame shows the 1st time: 这是我的框架第一次显示的内容: 在此处输入图片说明

And then after I resize it the values appear: 然后,我调整其大小后,将显示值: 在此处输入图片说明

在JTextField的父控件上调用doLayout()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM