编辑:当我拖动边框时,正在发送某种刷新,我需要弄清楚这一点并手动发送相同的刷新。
使用JFrame和JPanel显示框架时,我正在尝试使其变得易于更改。
我想做的是进行切换,以便可以在“小视图”和“大视图”之间切换。
但是,尝试执行以下操作时,面板的内容上会出现一个白色的条形图:
还有一个值得注意的地方是,拖动边框时,白色条会消失,并且可以正确地重新加载/刷新内容(即使只是少量拖动)
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.
}
}
答案 0 :(得分:-1)
由于将框架添加到面板中,请尝试在面板上调用validate()。