मुझे एक ही समस्या थी और कॉल सेट द्वारा इसे ठीक किया गया (सत्य); मैं जिस जेफ्रेम का उपयोग कर रहा था।
उदाहरण: साथ
jframe.setContentPane(new MyContentPane());
ठीक यह: अगर आपके JFrame उपयोग करने के बाद अपडेट नहीं करता
jframe.setContentPane(new MyContentPane());
jframe.setVisible(true);
मुझे पता है कि यह यह करने के लिए भले ही अपने JFrame पहले से ही दिख रहा है मूर्खतापूर्ण लगता है, लेकिन यह एकमात्र तरीका है जिसे मैंने इस समस्या को ठीक करने के लिए अभी तक पाया है (ऊपर प्रस्तावित समाधान मेरे लिए काम नहीं करता है)।
यहां एक पूरा उदाहरण है। इसे चलाएं और फिर "f.setVisible (true) को असम्बद्ध करें;" कक्षा पैनल 1 और पैनल 2 में निर्देश और आप अंतर देखेंगे। आयात को न भूलें (स्वचालित आयात के लिए Ctrl + Shift + O)।
मुख्य वर्ग:
public class Main {
private static JFrame f;
public static void main(String[] args) {
f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setContentPane(new Panel1(f));
f.pack();
f.setVisible(true);
}
}
Panel1 वर्ग:
public class Panel1 extends JPanel{
private JFrame f;
public Panel1(JFrame frame) {
f = frame;
this.setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
JButton b = new JButton("Panel 1");
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
f.setContentPane(new Panel2(f));
// Uncomment the instruction below to fix GUI "update-on-resize-only" problem
//f.setVisible(true);
}
});
add(b);
}
}
Panel2 वर्ग:
public class Panel2 extends JPanel{
private JFrame f;
public Panel2(JFrame frame) {
f = frame;
this.setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
JButton b = new JButton("Panel 2");
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
f.setContentPane(new Panel1(f));
// Uncomment the instruction below to fix GUI "update-on-resize-only" problem
//f.setVisible(true);
}
});
add(b);
}
}
आशा है कि मदद करता है।
सम्मान।
जॉन धन्यवाद, यह पूरी तरह से काम करता है! मूल्यवान इनपुट के लिए – nautilusvn
+1। बस एक सुझाव, ईडीटी के अंदर 'repaint()' कॉल डालने की कोई ज़रूरत नहीं है, क्योंकि किसी भी धागे से 'repaint() 'को कॉल करना सुरक्षित है, जैसा कि यहां बताया गया है [http://stackoverflow.com/questions/9786497/safe उपयोग करने के लिए-घटक-repaint-out-edt/9786598 # 97865 9 8) –
"स्विंग घटकों के उप-वर्ग जिनके पास यूआई प्रतिनिधि है ... को 'super.paintComponent()' "- [* पेंट विधि *] (http: //java.sun.com/products/jfc/tsc/articles/painting/index.html#callback)। – trashgod