gpt4 book ai didi

java - JSplitPane 未显示

转载 作者:行者123 更新时间:2023-11-30 03:01:12 25 4
gpt4 key购买 nike

我的 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);

有人可以帮忙吗?

最佳答案

我做了一些修改,它工作正常

    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();
}
}

工作正常

关于java - JSplitPane 未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35912774/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com