gpt4 book ai didi

Java Swing 拆分 Pane View 布局

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:20:54 25 4
gpt4 key购买 nike

你好,我正在实现我的第一个拆分 Pane View ,它似乎对我不起作用,我得到以下输出...

enter image description here

这是代码。

//Create Album Panel
albumPanel.setLayout(new FlowLayout());

//Add List view
albumList.setMinimumSize (new Dimension(150,150));
albumPanel.add(new JScrollPane(albumList));


//Add Text Area
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
textArea.setEditable(false);
textArea.setMinimumSize (new Dimension(150,150));
albumPanel.add(textArea);

//Split Pane
JSplitPane splitpane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, albumList, textArea);

albumPanel.add(splitpane, BorderLayout.CENTER);

最佳答案

您已经设置了albumPanel布局到 FlowLayout但你尝试使用 BorderLayout添加到 JSplitPane 时的常量:

albumPanel.add(splitpane, BorderLayout.CENTER);

你应该设置albumPanel布局到 BorderLayout通过new BorderLayout()

此外,让 LayoutManager 设置组件的大小也不是一个好主意。为您做。

关于Java Swing 拆分 Pane View 布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12544816/

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