javaswingjsplitpane

JSplitPane not painting correcting


In my application, I have a JFrame displaying a JSplitPane, with the split being VERTICAL_SPLIT. The top is displaying a JLabel, and the bottom is displaying a JInternalFrame. Two problems are occuring.

  1. The JLabel is displaying, but the JInternalFrame is not.

    2. I have to resize the application to have the JSplitPane display at all

I believe this is both linked to an incorrect use of JSplitPane. However, I have been unable to work out what. May I please have some help with this issue?

p.s. I have run tests to make sure GUIWindow.getInsideFrame() is not returning null. The instanceof checks at the end are saying that both components in the pane exist and are of that type. Thank you very much for all your help:

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!");
            }
            
        });
    }

EDIT: I fixed problem 2 with a call to frame.revalidate() at the start of the second synchronised(lock) block. This has been included in the code.


Solution

  • As I told you in comment, you simply need to use setVisible(true) on your JInternalFrame, else it will not be considered by your JSplitPane.

    This a really common mistake on java swing !

    I'm glad it helped you ;)