我创建了一个 TitledBorder 并将其设置为 JPanel。
JPanel panel = new JPanel();
panel.setBorder(javax.swing.BorderFactory.
createTitledBorder(null, "title", javax.swing.border.
TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.
TitledBorder.DEFAULT_POSITION, null, java.awt.Color.red));
现在我想改变边框标题文本的颜色;如果可能的话,边界线。我看到当我通过方法 titledborder.setTitleColor(theColor);
和 revalidate()
和 repaint()
更改边框的颜色时;表格面板不受影响。我还创建了 thiledBorder
的新实例并将其分配给面板;但没有效果。是否需要更新面板,然后将其设置为新的边框实例?谢谢
最佳答案
您没有说明 titledborder
是如何分配的,但它是这样工作的:
TitledBorder titledBorder = BorderFactory.createTitledBorder(...);
panel.setBorder(titledBorder);
然后在运行时:
titledBorder.setTitleColor(theColor);
repaint(); // revalidate not necessry
关于java - 在 java 中动态更改 TitledBorder 颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15879216/