我想添加JTable到JPanel其布局中null. JPanel包含其他组件.我必须添加JTable适当的位置.
在java编程工作了近4年之后,我决定学习如何自己编写GUI类,因为到目前为止我一直使用NetBeans GUI编辑器(我并不为此感到特别自豪,但它已经很好地避免了我对组件的担心布局).
问题是我正在关注如何使用GroupLayout教程来了解我觉得非常强大的布局管理器.现在我自己做了一个小例子,然后尝试在Netbeans GUI Editor中做同样的事情,我发现两个代码之间存在一些差异,我想知道我是否遗漏了某些内容,或者NetBeans只是在GroupLayout定义中添加了无用的代码.
这是我的目标:

这是我的SSCCE:
public static void main(String[] args) {
JLabel label = new JLabel("This is a test");
label.setFont(new Font("Segoe UI Semibold", Font.BOLD | Font.ITALIC, 24));
JSeparator separator = new JSeparator(JSeparator.HORIZONTAL);
DefaultListModel model = new DefaultListModel();
model.addElement("Apple");
model.addElement("Orange");
model.addElement("Kiwi");
model.addElement("Watermelon");
JList list = new JList(model);
list.setPreferredSize(new Dimension(400, 300));
JScrollPane scrollPane = new JScrollPane();
scrollPane.setViewportView(list);
JFrame frame = new JFrame("Test");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
Container contentPane = frame.getContentPane();
GroupLayout layout = new GroupLayout(contentPane);
layout.setAutoCreateContainerGaps(true);
contentPane.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING) …Run Code Online (Sandbox Code Playgroud)