그래서이 시점에서 JPanel
이 포함 된 간단한 JFrame
을 가지고 있습니다. (즉 contentPane
가 JPanel
가요이다.)를 JInternalFrame
현재 JFrame
변환하는 버튼으로 JFrame
의 메뉴 바있다 - 그것의 세트에 JFrame
의 contentPane
JDesktopPane
을 기존 내부이었다 JPanel
이동 JFrame
을 새로 생성 된 JInternalFrame
-에 추가하고 JPanel
이 새겨진 두 번째 JInternalFrame
을 만듭니다.문제 표시 할 JInternalFrame 가져 오기
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
가 더 높은 우선 순위를지고 있음을 보인다이다 : 여기에 내 코드입니다. 즉,이 코드가 실행 된 후에는 두 개의 JInternalFrames
이 보이지 않습니다. JDesktopPane
이 표시됩니다. 그리고 크기 또는 위치가 JInternalFrame
인 문제 때문이 아닙니다. 나는 광범위하게 (arrangeHorizontally()
메소드 이후에 크기와 위치를 출력하여) 확인했다. 그래서 나는 잃어 버렸다. 어떤 도움이 필요합니까?
SSCCE : 작업을해야 그 .. 좋아, 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] (http://sscce.org/)를 제공해야합니다. – MadProgrammer
@MadProgrammer 동일하게 작동하는 하나를 추가했습니다. 나는 아직 그것을 시험하지 않았지만 그렇게하려고하고있다. –
이상하게도, 예제는 훌륭하게 작동합니다. 나는 그것을 약간 변형 시켰지만, 그것은 나를 위해 일하는 것 같다. – MadProgrammer