だから、私はこの時点で、その中に単純なものJFrame
がある単純なものを持ってJPanel
います。(つまり、それはcontentPane
です。)現在をに変換するボタンJPanel
のあるメニューバーがあります-それは'を既存のものに設定し、中にあったものを新しく作成されたものに移動します-そして作成しますその中に新しいものがあります。これが私のコードです:JFrame
JFrame
JInternalFrame
JFrame
contentPane
JDesktopPane
JPanel
JFrame
JInternalFrame
JInternalFrame
JPanel
if(ae.getActionCommand().equals("newWindow"))
{
if(jdp.getComponentCount() > 0)//jdp is the pre-existing JDesktopPane
{
//All of the code in this if statement works fine. It's the else in which I am getting problems.
DefaultInternalFrame dif = new DefaultInternalFrame();//DefaultInternalFrame is an extension of JInternalFrame which is literally nothing more than a JInternalFrame right now.
jdp.add(dif);
dif.setContentPane(new DefaultPanel());//Much like DefaultInternalFrame, DefaultPanel is just an extension of JPanel which I plan on adding to, but have not yet.
dif.setVisible(true);
dif.moveToFront();
}else
{
//Again, this is where I'm having issues..
DefaultPanel dp = (DefaultPanel)baseFrame.getContentPane();
jdp.setVisible(true);
baseFrame.setContentPane(jdp);
DefaultInternalFrame dif = new DefaultInternalFrame();
jdp.add(dif);
dif.setContentPane(dp);
dif.setVisible(true);
dif.moveToFront();
DefaultInternalFrame dif2 = new DefaultInternalFrame();
jdp.add(dif2);
dif2.setContentPane(new DefaultPanel());
dif2.setVisible(true);
dif2.moveToFront();
}
arrangeHorizontally();//This takes care of resizing and relocating the JInternalFrames. (It is definitely not the problem.)
}
私が抱えている問題は、JDesktopPane
が優先度が高くなっているように見えることです。つまり、このコードが実行された後、2つは表示されませんが、が表示されJInternalFrames
ますJDesktopPane
。そして、それはサイズや場所の問題によるものではありませんJInternalFrame
。私はそれを広範囲にチェックしました(arrangeHorizontally()
メソッドの後にサイズと場所を印刷することによって)。それで、私は途方に暮れています。何か助けはありますか?
SSCCE:
private static JFrame f;
private static JDesktopPane desktop;
public static void main(String[] args) throws InterruptedException
{
desktop = new JDesktopPane();
f = new JFrame("Test");
f.setPreferredSize(new Dimension(500,500));
f.setContentPane(new JPanel());
f.pack();
f.setVisible(true);
Thread.sleep(4000); //Just so you can see the before/after
JPanel panel = (JPanel)f.getContentPane();
desktop.setVisible(true);
f.setContentPane(desktop);
JInternalFrame inFrame = new JInternalFrame("1");
desktop.add(inFrame);
inFrame.setContentPane(panel);
inFrame.setPreferredSize(new Dimension(200,200));//Just some random size; doesn't matter.
inFrame.pack();
inFrame.setVisible(true);
JInternalFrame inFrame2 = new JInternalFrame("2");
desktop.add(inFrame2);
inFrame2.setContentPane(new JPanel());
inFrame2.setPerferedSize(new Dimension(200,200));
inFrame2.pack();
inFrame2.setVisible(true);
}
それはうまくいくはずです..さて、SSCCEは実際に正常に機能します..それは私に不思議に思います、なぜ元の機能がないのですか?