![](/img/trans.png)
[英]How do I change the button text in an internationalized message box in Swing
[英]Enable text highlighting in swing message-box
假设我使用以下代码在我的简单swing应用程序中提示错误消息:
JOptionPane.showMessageDialog(null, message, "Error", JOptionPane.ERROR_MESSAGE);
有什么方法可以让用户突出显示文本部分(用于复制/粘贴目的)?
非常感谢。
尝试这个
JTextArea textarea= new JTextArea("add your message here");
textarea.setEditable(true);
JOptionPane.showMessageDialog(null, textarea, "Error", JOptionPane.ERROR_MESSAGE);
JOptionPane可以用任何对象构造,而不仅仅是字符串消息。 因此,您可以构造一个JTextArea并将其作为消息传递给JOptionPane。 这应该允许复制粘贴。
如果您反对默认JTextArea显示的白色背景,则可以将JTextArea背景颜色设置为等于JOptionPane的背景颜色。
String title = "foo";
String message = "Select me";
JTextArea msg = new JTextArea(message);
JOptionPane pane = new JOptionPane(msg, JOptionPane.INFORMATION_MESSAGE);
msg.setBackground(pane.getBackground());
JDialog dialog = pane.createDialog(null, title);
dialog.setVisible(true);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.