2016-08-23 31 views
2

在我的应用程序中,我有一个JFrame显示JSplitPane,分割为VERTICAL_SPLIT。顶部显示一个JLabel,底部显示一个JInternalFrame。发生两个问题。JSplitPane没有绘画修正

  1. JLabel被显示,但JInternalFrame不是。

    2.我在所有

我相信这是首尾相连的不正确使用的JSplitPane来调整应用程序有JSplitPane显示。但是,我一直无法解决什么问题。我可以帮助解决这个问题吗?

p.s.我已经运行测试以确保GUIWindow.getInsideFrame()未返回null。最后的instanceof检查表示该窗格中的两个组件都存在且属于该类型。非常感谢您对您的帮助:

protected static void newWindow(GUIFrame window) { 
     SwingUtilities.invokeLater(new Runnable(){ 

      @Override 
      public void run() { 
       JSplitPane pane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); 
       JInternalFrame intFrame = window.getInsideFrame(); 
       pane.setRightComponent(intFrame); 
       pane.setLeftComponent(new JLabel(window.getDescription())); 
       synchronized(lock){ 
        frame.remove(currentPane); 
        frame.add(pane); 
       } 
       synchronized(lock){ 
        frame.revalidate(); 
        pane.setVisible(true); 
        frame.repaint(); 
        if(window instanceof ColourFrameShower) return; 
        currentWindow = window; 
        currentPane = pane; 
        currentFrame = intFrame; 
       } 
       if(pane.getLeftComponent() instanceof JLabel) System.out.println("JLabel exists!"); 
       else System.out.println("JLabel does not exist!"); 

       if(pane.getRightComponent() instanceof JInternalFrame) System.out.println("JInternalFrame exists!"); 
       else System.out.println("JInternalFrame does not exist!"); 
      } 

     }); 
    } 

编辑:我固定的问题2在第二synchronised(lock)块的开始frame.revalidate()通话。这已包含在代码中。

+0

谢谢 – JD9999

+0

你试图显示只有你的JInternalFrame编辑:),没有JSplitPanel?它工作吗? :) – Kapcash

+0

是的,没有JSplitPanel它正在工作。在我的github上查看整个应用程序的最新版本:https://github.com/JD9999/GUI-of-everything – JD9999

回答

1

正如我在评论中告诉您的,您只需在JInternalFrame上使用setVisible(true),否则它将不会被您的JSplitPane考虑。

这是java swing上真正常见的错误!

我很高兴它帮助你;)

0

尝试设置resizeWeight:pane.setResizeWeight(0.5);

+0

这对我无能为力,但感谢您的快速响应! :) – JD9999