下面是代码和屏幕。
JPanel tableListPanel = new JPanel(new BorderLayout(5, 5));
tableListPanel.setPreferredSize(new Dimension(150, 100));
tableListPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(0, 5, 5, 5),
BorderFactory.createTitledBorder("Added Tables")));
PosButton btnRemoveTable = new PosButton("REMOVE");
// code to add lable.
tableListPanel.add(new JLable("Test")):
最佳答案
更改此行:
tableListPanel.add(new JLabel("Test")):
对于:
tableListPanel.add(new JLabel("Test"), BorderLayout.WEST):
//You can also use BorderLayout.EAST, BorderLayout.NORTH or BorderLayout.SOUTH
编辑:
可能还想更改此设置(仅当第一个更改本身不起作用时):
JPanel tableListPanel = new JPanel(new BorderLayout(5, 5));
对于:
JPanel tableListPanel = new JPanel(new BorderLayout());
2017 年 10 月 3 日编辑:
将 JLable 更改为 JLabel。
关于java - 无法在 JPanel 中添加标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34062669/