无法在JPanel中添加标签

时间:2015-12-03 09:50:05

标签: java swing jpanel

我想在JPanel中添加标签。enter image description here

以下是代码和屏幕。

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")):

1 个答案:

答案 0 :(得分:0)

更改此行:

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

EDITED 10/03/2017:

为JLabel更改了JLable。