【问题标题】:Change JOptionPane Button attributes and background color更改 JOptionPane 按钮属性和背景颜色
【发布时间】:2014-11-21 10:34:07
【问题描述】:

我已使用 UIManager 设置修改了 JOptionPane 的字体,但我无法找到更改按钮属性的属性。 例如。我想删除文本周围的边框,如下所示。我还想删除 Y 和 N 下的下划线,如下所示。

此外,我可以将 JOptionPane 的背景颜色从这种 Off-White 颜色更改为其他颜色吗?

【问题讨论】:

标签: java swing button joptionpane


【解决方案1】:

您可以更改单个对话框:

您需要一个 customJDialog 和一个自定义 JOptionPane。按钮在与助记符匹配的第一个字母下划线。将其更改为不使用的东西。矩形是关于按钮焦点的。

JDialog dialog = new JDialog();

JOptionPane pane = new JOptionPane("Some Message",
JOptionPane.PLAIN_MESSAGE, JOptionPane.YES_NO_OPTION);

List<JButton> list = SwingUtils.getDescendantsOfType(JButton.class, pane);
//this method is part of the SwingUtils. It is free to use. You can download it from the link.

pane.setBackground(Color.green); //this does not completely change the background. I am not sure how you can change it completely

for (JButton b : list) {
    b.setMnemonic(0); //call it with an int or char that does not exist in your button.
    b.setFocusable(false); //removes the rectangle
    b.setBackground(Color.red);
    //you can do more since you have direct access to the button
}

如果您没有使用 java 自定义 JOptionPane 的经验,请查看此按钮操作:Pressing Yes/No on embedded JOptionPane has no effect

SwingUtil 链接:http://tips4java.wordpress.com/2008/11/13/swing-utils/

如果你想把代码变成库读:http://www.programcreek.com/2011/07/build-a-java-library-for-yourself/

【讨论】:

  • 如果它有效,那就太棒了!谢谢..我很快就会试试这个:)
猜你喜欢
  • 2015-06-04
  • 1970-01-01
  • 2012-02-22
  • 1970-01-01
  • 2021-06-22
  • 2015-04-03
相关资源
最近更新 更多