【问题标题】:JSplitPane isn't shownJSplitPane 未显示
【发布时间】:2016-03-10 09:43:56
【问题描述】:

我的 JSplitPane 有问题,我将组件设置为 JSplitPane 但没有显示任何内容。 代码如下:

/**__COMPONENT OBJECTS__**/
    JFrame frame = new JFrame();
    JPanel leftPane = new JPanel();
    JPanel rightPane = new JPanel();
    JTextArea textArea = new JTextArea();
    JButton button = new JButton("LOL");
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);

    /**__SPLITPANE-PROPS__**/
    splitPane.setLeftComponent(leftPane);
    splitPane.setRightComponent(rightPane);
    splitPane.setLayout(null);
    splitPane.setSize(frame.getWidth(), frame.getHeight() - menuBar.getHeight());
    splitPane.setVisible(true);
    splitPane.setLocation(0,menuBar.getHeight());
    int ht = splitPane.getHeight();

    /**__RIGHTPANE-PROPS__**/
    rightPane.add(textArea);
    rightPane.setSize(500, ht);
    rightPane.setVisible(true);

    /**__LEFTPANE-PROPS__**/
    leftPane.add(button);
    leftPane.setSize(100, ht);
    leftPane.setVisible(true);

    /**__FRAME-PROPS__**/
    frame.setJMenuBar(menuBar);
    frame.add(splitPane);
    frame.setLayout(new GridLayout());
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    frame.setSize(500,400);
    frame.setVisible(true);

有人可以帮忙吗?

【问题讨论】:

    标签: java swing jsplitpane


    【解决方案1】:

    我已经做了一些修改它的工作正常

        public class ddd
    {
    
        JFrame frame = new JFrame();
        JPanel leftPane = new JPanel();
        JPanel rightPane = new JPanel();
        JTextArea textArea = new JTextArea();
        JButton button = new JButton("LOL");
        JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    
    
        public ddd()
        {
        /** __COMPONENT OBJECTS__ **/
    
    
        splitPane.setLeftComponent(leftPane);
        splitPane.setRightComponent(rightPane);
        splitPane.setLayout(null);
    //  splitPane.setSize(frame.getWidth(), frame.getHeight() - menuBar.getHeight());
        splitPane.setVisible(true);
    //  splitPane.setLocation(0, menuBar.getHeight());
    
        /** __RIGHTPANE-PROPS__ **/
        rightPane.add(textArea);
        rightPane.setSize(500, 100);
        rightPane.setVisible(true);
    
    
        /** __LEFTPANE-PROPS__ **/
        leftPane.add(button);
        leftPane.setSize(100, 100);
        leftPane.setVisible(true);
    
        /** __FRAME-PROPS__ **/
        frame.add(splitPane);
        frame.setLayout(new GridLayout());
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.setSize(500, 400);
        frame.setVisible(true);
        }
    
        public static void main(String[] args)
        {
        new ddd();
        }
    }
    

    一切正常

    【讨论】:

    • 好的,我试试这个。谢谢;)
    【解决方案2】:

    没关系,问题如下: 我将JSplitPanel 设置为JFrame 大小,但JFrame Size 是在方法结束时设置的...... -.-

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-13
      相关资源
      最近更新 更多