编辑:当我拖动边框时正在发送某种刷新,我需要弄清楚并手动发送相同的刷新。
- 请注意,我已尝试使用 revalidate() 和 repaint()。
当使用 JFrame 和 JPanel 显示框架时,我试图使框架的大小易于可变。
我想做的是进行切换,这样我就可以在“小 View ”和“大 View ”之间切换。
但是,在尝试执行以下操作时,面板的内容上会出现一个白条:
- 开放式框架...(默认为大尺寸)
- 设置为小尺寸
- 再次设置为大尺寸
- 再次设置为小尺寸(这是出现白条的时候) (引用main方法中的注释)
此外,值得注意的是,当您拖动边框时(即使您拖动的只是少量),白色条会消失并正确地重新加载/刷新内容
public class FrameTest {
private static FrameTest instance;
JFrame clientFrame
JPanel client_panel;
private void openFrames() {
JclientFrame = new JFrame("727 Deob");
clientFrame.setLayout(new BorderLayout());
client_panel = new JPanel();
client_panel.setLayout(new BorderLayout());
client_panel.add(new Applet());
client_panel.setPreferredSize(new Dimension(765, 555));
clientFrame.getContentPane().add(client_panel, BorderLayout.PAGE_END);
clientFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
clientFrame.pack();
clientFrame.setVisible(true);
}
public static void main(String[] args) {
instance = new FrameTest();
instance.openFrames();
instance.setDimensions(true); //works absolutely fine!
instance.setDimensions(false); //continues to work absolutely fine!
instance.setDimensions(true); //now the white bar at the bottom appears
}
public void setDimensions(boolean smallType) {
int width = 765;
int height = smallType ? 530 : 577;
clientFrame.setSize(width, height);
//tried using revalidate() and repaint() here on the frame, the frame contents AND the panel... NO LUCK, white bars still aren't fixed.
}
}
最佳答案
由于Frame被添加到Panel,尝试调用panel的validate()
关于java - JFrame JPanel 刷新/更新/重绘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52405303/