【发布时间】:2021-02-16 10:21:21
【问题描述】:
我已经看过其他类似的关于如何做到这一点的帖子,但我不明白其中任何一个。他们中的大多数使用这个名为“TitledBorder”的对象,但我只是使用方法“.setBorder()”。我也想改变边框的颜色和标题的颜色。请帮帮我,谢谢!
private void layoutView()
{
//The JPanel that holds the JTextField. This is the first
//JPanel that I want to change the color of the titled border
JPanel question = new JPanel();
question.add(this.question);
question.setBorder(BorderFactory.createTitledBorder("Ask a question"));
//The JPanel that holds the JLabel.
//This is the second JPanel that I want to change the colour of.
JPanel questionAnswerPanel = new JPanel();
questionAnswerPanel.add (this.questionAnswer);
questionAnswerPanel.setBorder(BorderFactory.createTitledBorder("Prediction"));
//The JPanel that holds the question JPanel so it can be centered
JPanel center = new JPanel();
center.setLayout(new BorderLayout());
center.add(question, BorderLayout.CENTER);
//The complete layout
this.setLayout(new BorderLayout());
this.add(center, BorderLayout.CENTER);
this.add(questionAnswerPanel, BorderLayout.SOUTH);
}
【问题讨论】:
标签: java swing user-interface awt