The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Read only edit box
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  

Posts: 93
Registered: 12/6/04
Read only edit box
Posted: Oct 23, 2012 7:07 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Hello, I am attempting to make a read-only edit box that allows the user to click and select text for copy operations, however I would like to prevent the user from modifying the contents. The easy way to make an edit box read-only is to set "enable" to "off", however this prevents the user from selecting and copying text. I've looked into using a keypressfcn to reset the string after any key press. This kind of works, however it only resets the string after enter is pressed.

This problem is similar to reading the string property during a keypressfcn callback, which itself has issues explained here:

I've looked into using a similar approach by setting the "KeyTypedCallback" on the java object returned by findjobj, and then calling "setText" inside the callback. This does work on the GUI, however the matlab command prompt complains of a java null pointer exception (below). Any thoughts on how to prevent this? Or any thoughts on other ways to accomplish a read only edit box?

Thanks. (PS This is on Matlab R2010B)

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.plaf.basic.BasicTextUI.getVisibleEditorRect(Unknown Source)
at javax.swing.plaf.basic.BasicTextUI.paintSafely(Unknown Source)
at javax.swing.plaf.basic.BasicTextUI.paint(Unknown Source)
at javax.swing.plaf.basic.BasicTextUI.update(Unknown Source)
at javax.swing.JComponent.paintComponent(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintToOffscreen(Unknown Source)
at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(Unknown Source)
at javax.swing.RepaintManager$PaintManager.paint(Unknown Source)
at javax.swing.RepaintManager.paint(Unknown Source)
at javax.swing.JComponent._paintImmediately(Unknown Source)
at javax.swing.JComponent.paintImmediately(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.seqPaintDirtyRegions(Unknown Source)
at javax.swing.SystemEventQueueUtilities$ Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at Source)

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.