首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JSplitPane未显示

JSplitPane未显示
EN

Stack Overflow用户
提问于 2016-03-10 09:43:56
回答 2查看 41关注 0票数 1

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

代码语言:javascript
复制
/**__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);

有人能帮忙吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-03-10 11:55:43

我做了一些修改,它的工作很好。

代码语言:javascript
复制
    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
EN

Stack Overflow用户

发布于 2016-03-10 10:10:40

没关系,问题是:我用JSplitPanel大小设置了JFrame,但是在方法的末尾设置了JFrame大小.-.-

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35912774

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档