我正在尝试构建一个GUI界面。我制作了包装面板,其标题是"员工详细信息"如下面的屏幕截图所示:
我使用以下代码在边框上设置标题
wrapper.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Staff Details",TitledBorder.CENTER, TitledBorder.TOP));
现在我想将标题更改为"查看详细信息"当我点击"查看"按钮。我该怎么做?
答案 0 :(得分:2)
将button
替换为“查看详细信息按钮”的实际名称
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
//Execute stuff when button is pressed
}
});
答案 1 :(得分:1)
可能保留TitledBorder
参考
TitledBorder titledBorder = BorderFactory.createTitledBorder(...);
然后你应该只能setTitle()
titledBorder.setTitle("New Title");
repaint();
答案 2 :(得分:0)
panel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Your Title", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Font", 0, 18)));