[kepler-dev] [Bug 4147] - Error message with selectable text
bugzilla-daemon at ecoinformatics.org
bugzilla-daemon at ecoinformatics.org
Fri Jun 12 19:53:20 PDT 2009
http://bugzilla.ecoinformatics.org/show_bug.cgi?id=4147
cxh at eecs.berkeley.edu changed:
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|berkley at nceas.ucsb.edu |cxh at eecs.berkeley.edu
Severity|minor |enhancement
Status|ASSIGNED |NEW
------- Comment #3 from cxh at eecs.berkeley.edu 2009-06-12 19:53 -------
I'm lowering the priority of this and changing it to an enhancement because
the code works as expected.
I agree that it would be nice if the dialog text was selectable, retyping
an error message is a waste of human effort.
ptolemy.gui.GraphicalMessageHandler extends
ptolemy.gui.UndeferredGraphicalMessageHandler which uses JOptionPane.
It appears to be a limitation of JOptionPane that the text is not selectable.
See http://java.sun.com/docs/books/tutorial/uiswing/components/dialog.html
for JOptionPane examples,
However, all is not lost. JOptionPane has a message argument and if that
argument is a String, then a JLabel is created.
http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JOptionPane.html says:
--start--
message
A descriptive message to be placed in the dialog box. In the most common
usage, message is just a String or String constant. However, the type of this
parameter is actually Object. Its interpretation depends on its type:
Object[]
An array of objects is interpreted as a series of messages (one per
object) arranged in a vertical stack. The interpretation is recursive -- each
object in the array is interpreted according to its type.
Component
The Component is displayed in the dialog.
Icon
The Icon is wrapped in a JLabel and displayed in the dialog.
others
The object is converted to a String by calling its toString method. The
result is wrapped in a JLabel and displayed.
--end--
So instead of passing a String, I created a method that creates a JTextArea
that looks like a JLabel, but is selectable. I found code at
http://www.rgagnon.com/javadetails/java-0296.html
that got me most of the way there.
So, I modified ptolemy.gui.UndeferredGraphicalMessageHandler so that we
use a JTextField, which looks like a JLabel, but is selectable.
As a fallback, we will return a String if there is a problem.
More information about the Kepler-dev
mailing list