f



JTextField - how to disable selecting text in this component?

Hi!

Has anybody an idea, how to do it? I'll be lucky.

Regards, dako

0
hidi (1)
12/28/2006 10:28:51 AM
comp.lang.java.gui 8286 articles. 0 followers. Post Follow

14 Replies
6753 Views

Similar Articles

[PageSpeed] 7

dako wrote:
> Hi!
>
> Has anybody an idea, how to do it? I'll be lucky.
>
> Regards, dako

Have you tried JTextField.setEditable(false) ?

If this isn't the problem could you try and make the problem a bit
clearer?

Mearvk

0
mearvk
12/28/2006 10:37:35 AM
mearvk napisal(a):
> dako wrote:
> > Hi!
> >
> > Has anybody an idea, how to do it? I'll be lucky.
> >
> > Regards, dako
>
> Have you tried JTextField.setEditable(false) ?
>
> If this isn't the problem could you try and make the problem a bit
> clearer?
>
> Mearvk

OK, I'll try explain the problem more clearly :)  even though I have't
felt comfortable writing EN yet...

I don't need to disable selecting the component for a while or ages...,
but only text within the component.

I hope, it's an enough discribe my problem.

1
dako
12/28/2006 11:16:16 AM
dako wrote:
> mearvk napisal(a):
>> dako wrote:
>>> Hi!
>>>
>>> Has anybody an idea, how to do it? I'll be lucky.
>>>
>>> Regards, dako
>> Have you tried JTextField.setEditable(false) ?
>>
>> If this isn't the problem could you try and make the problem a bit
>> clearer?
>>
>> Mearvk
> 
> OK, I'll try explain the problem more clearly :)  even though I have't
> felt comfortable writing EN yet...
> 
> I don't need to disable selecting the component for a while or ages...,
> but only text within the component.
> 
> I hope, it's an enough discribe my problem.
> 

setEnabled(false) and setEditable(false) are different and 
setEditable(false) would be what you want to prevent people from putting 
text in it. Disabling the component is done by setEnabled() which wasn't 
what Mearvk proposed to you.
0
Brandon
12/28/2006 10:37:59 PM
Brandon McCombs napisal(a):
>
> setEnabled(false) and setEditable(false) are different and
> setEditable(false) would be what you want to prevent people from putting
> text in it. Disabling the component is done by setEnabled() which wasn't
> what Mearvk proposed to you.

Sorry. I forgotten say I don't want to prevent component from puting
text in it but only whilst selecting text in it. Is it imposible?

0
dako
12/29/2006 7:21:00 AM
Brandon McCombs napisal(a):
>
> setEnabled(false) and setEditable(false) are different and
> setEditable(false) would be what you want to prevent people from putting
> text in it. Disabling the component is done by setEnabled() which wasn't
> what Mearvk proposed to you.

Sorry. I forget say I don't want to prevent component from puting text
in it but only whilst selecting text in it. Is it imposible?

0
dako
12/29/2006 7:21:20 AM
dako wrote:
> Brandon McCombs napisal(a):
> >
> > setEnabled(false) and setEditable(false) are different and
> > setEditable(false) would be what you want to prevent people from putting
> > text in it. Disabling the component is done by setEnabled() which wasn't
> > what Mearvk proposed to you.
>
> Sorry. I forget say I don't want to prevent component from puting text
> in it but only whilst selecting text in it. Is it imposible?

Try subclassing JTextField. When the mouseDrag event fires inside the
JTextField do something like return immediately or set the focus on the
parent JComponent. You will want to catch keyboard input also. (Block
things like ctrl+A, ctrl+C, shift+end and shift+home)

I think it can be done but it will require some hacking and time. There
may be a better way but this is what I can figure.

Good luck,

Mearvk

0
mearvk
12/29/2006 12:53:34 PM
mearvk wrote:
> dako wrote:
....
> > ...I forget say I don't want to prevent component from puting text
> > in it but only whilst selecting text in it. Is it imposible?
.....
> I think it can be done but it will require some hacking and time. There
> may be a better way ...

How about - an entirely different /strategy/ in
following 'the path of least surprise' in the use
of GUI components?

It is nonsensical to allow editing of a text field, but
disallow selecting the text (I would normally select
the text simply to delete the content, but if this
scheme were implemented - i'd need to hit 'del, del,
del, del, ..oh heck I'll just use the software of their
direct competitor, instead..').

Andrew T.

0
Andrew
12/29/2006 1:34:32 PM
> Sorry. I forget say I don't want to prevent component from puting text
> in it but only whilst selecting text in it. Is it imposible?

Try to use a JLabel instead. 

Bye.
-- 
Real Gagnon  from  Quebec, Canada
* Looking for Java or PB code examples ? Visit Real's How-to  
* http://www.rgagnon.com/howto.html
0
Real
12/29/2006 8:37:48 PM
dako wrote:
> Hi!
>
> Has anybody an idea, how to do it? I'll be lucky.
> 
> Regards, dako

You might try JTextField.setHighlighter(null);

John

1
John
1/3/2007 4:39:19 PM
Hi John!

Thx a lot! That is the thing in comparision with rest of comments :)
The highlighter sounded familiar but I did't think about the null :|

Regards, dako

0
dako
1/4/2007 9:06:00 AM
Real Gagnon napisal(a):

> Try to use a JLabel instead.

I've already known the solution thanks to John. I might try
JTextField.setHighlighter(null) so the idea is redundant.

Regards, dako

0
dako
1/4/2007 9:15:08 AM
mearvk napisal(a):

> Try subclassing JTextField. When the mouseDrag event fires inside the
> JTextField do something like return immediately or set the focus on the
> parent JComponent. You will want to catch keyboard input also. (Block
> things like ctrl+A, ctrl+C, shift+end and shift+home)
>
> I think it can be done but it will require some hacking and time. There
> may be a better way but this is what I can figure.
>

The solution is easier than you think ;) Look at John's post.

Regards, dako.

0
dako
1/4/2007 9:36:53 AM
Andrew Thompson napisal(a):
> It is nonsensical to allow editing of a text field, but
> disallow selecting the text....

Sorry, but I don't agree with you. It is't nonsensical. You should
remember that necessity is the mother of invention. Apparently somebody
needed the solution as well, because exist special method:

jTextField_userStreet.setHighlighter(null); 

Regards, dako.

1
dako
1/4/2007 10:04:10 AM
dako wrote:
> Hi John!
> 
> Thx a lot! That is the thing in comparision with rest of comments :)
> The highlighter sounded familiar but I did't think about the null :|
> 
> Regards, dako
> 

All this does is prevent the display of the highlighting color.  The caret still moves, and text is still selected and 
can still be cut and pasted.  I doubt this is the behavior you want.

The key question is why do you want to allow typing but not selection?  Is it to prevent cut/copy/paste? If so, remove 
the cut copy and paste actions from the action map of the JTextField.

It is not always enough to say what you want.  Sometimes you have to say why you want it in order from the proper 
solution to be offered.

Jim S.

-- 
Remove my extraneous mandibular appendages to reply via email.
0
Jim
1/9/2007 2:30:08 PM
Reply:

Similar Artilces:

trying to disable a text input field when a particular select list option is selected in a select field but this code has no effect
<script> $(document).ready(function () { $('#select_field').change(function(e) { if (e.target.value=='select_value') {e.second_field.disabled = true;} }) }) </script> On 2015-11-30 05:23, fugee279@gmail.com wrote: > <script> > $(document).ready(function () { > $('#select_field').change(function(e) > { > if (e.target.value=='select_value') {e.second_field.disabled = true;} > }) > }) > </script> Next time, please include the error message you see in the console. The para...

current selected text to highlighted text on mouse up event through java script
hi everybody, I want to convert the current selected text to highlighted text i.e. to yellow background on mouse up event on pdf form through java script. pls help me out. Thanks in advance regards Tanmay ...

how to disable text selection with addEventListener?
example: function disableText() { return false; } document.addEventListener("mousedown", disableText, false); i search many examples that use document.onmousedown = sidableText, so, how to disable text selection with addEventListener? thanks mask wrote: > function disableText() { return false; } > > document.addEventListener("mousedown", disableText, false); function disableText (evt) { if (typeof evt.preventDefault != 'undefined') { evt.preventDefault(); } } -- Martin Honnen http://JavaScript.FAQTs.com/ > > ...

java.lang.Set with elements of type java.lang.Set
Roughly I do something along the lines of: Set set = new HashSet(); Set elem = new HashSet(); set.add(elem); // now we change the elem and add it again to the set elem.add(some object here); set.add(elem); I found out the hard way that 'set' may now contain 'elem' either once or twice, the reason being that 'elem.add()' changes the hashCode of elem such that it is not noticed that it is in 'set' already on the 2nd 'set.add()'. Question: What I would actually want is an IdentityHashSet() set = new IdentityHashSet() but this does not...

How to disable text selection? (css?)
Is there any way to disable text selection in a web page (or at least render it invisible to the user)? If there is a way to control how selected text and its background are rendered, then the desired effect could be achieved by setting these parameters to match those of regular text. In this way, even if text was selected, the user would not see that it was. (I thought that this is something that may be controlled through css, but I have not been able to find anything in my css book, or in my google searches. Maybe I'm not using the right search keywords.) Thanks...

getting selection from disabled text window
I have a text window that I do not want the user to edit but from which I want the user to be able to copy the selection and paste it into another window. This appears to be impossible. When the window is disabled, selecting some text in it results in the selected region being highlighted as usual, but the selection is not available when I try to paste it into another window. If I change the state of the text window to normal, the selection becomes available. Is this the intended behavior or is it a bug? (This is with Tcl/Tk 8.4 under GNU/Linux.) If it is the intended behavior, is there a way to do what I want to do? Bill -- Bill Poser, Linguistics, University of Pennsylvania http://www.ling.upenn.edu/~wjposer/ billposer@alum.mit.edu "William J Poser" <wjposer@unagi.cis.upenn.edu> wrote > I have a text window that I do not want the user to edit but from > which I want the user to be able to copy the selection and paste it > into another window. This appears to be impossible. When the window > is disabled, selecting some text in it results in the selected > region being highlighted as usual, but the selection is not > available when I try to paste it into another window. If I change > the state of the text window to normal, the selection becomes > available. > > Is this the intended behavior or is it a bug? (This is with Tcl/Tk > 8.4 under GNU/Linux.) If it is the intended behavior, is there a way > to do what I want to...

[wxGTK] wxStyledTextCtrl
Hi, What can I do to disable select text ? Which events I must attend to deisable this service ? Thank's Mauro Cordon -)----- producao@scordon.com.br -> comercial mcordon@usa.com -> pessoal mcordon@programmer.net -> hobby Linux User -> #347961 ICQ ID -> #124551451 ----------------------------------------------- To Beer or Not To Beer, This Is Bohemia, ShakesBeer. -- ___________________________________________________________ Sign-up for Ads Free at Mail.com http://promo.mail.com/adsfreejump.ht...

select text in Gui Edit Box
Hi everyone, I have a GUI where there is an edit box that is populated with text. I would like to be able to select a portion of that text and send it along to another interface to be used or processed. get(handles.edit,'string') gives me the entire contents of the edit box where I am only interested in the highlighted part. get(handles.edit,'selection') gives me the on/off state of the selection property. I have also tried to use a robot to hit Ctrl-C for me, but the clipboard does not update dynamically. Please let me know if you have any ideas. Also please give detailed e...

Error occurred during intialization of VM java/lang/NoClassDefFoundError: java/lang/Object
Good day to all, I have installed the j2se/netbeans binary bundle on red hat 9. I can run everything perfectly as root but when I try to compile with any other user I get: Error occurred during intialization of VM java/lang/NoClassDefFoundError: java/lang/Object When I saw this it seemed like a permissions problem but I checked the permissions and everything seemed fine. All users have execute permissions of javac and java. I have read other threads dealing with the same or similar problem but have not reached any solution yet. I would appreciate if anyone that has run into this type of problem and has solved it if he/she could give me a hand or if anyone could just point out what I should be looking for in this type of problem. Thanks in advance... gek ...

GUI: Selecting Text in Edit boxes
This should be an easy one but i just can't find it in the help files: I have created a GUI with several edit text boxes which the user will tab through while inputting data. My problem is that windows applications generally highlight the contents of the edit box when you tab to it. This means that any keypress will delete the previous contents of the box and replace it with new data. Matlab does not do this by default so the contents of the box has to be deleted before new contents can be entered which is time consuming. Can anyone help and give me the code or even a useful command whi...

How To Retrieve Selected Text in Edit In GUI ?
Greeting , I would like to retrieve a selected piece of a string in an edit in a gui , the thing is I don't know How i can do that I assume there is a sort of instant system variable that automatically stores the selected values .. any ideas ? ...

How to disable components in GUI MATLAB temporarily?
i am implementing AHP using GUI. i have developed the code. i am having problem with disabling the components. for example i want to disable all the other radio buttons when one is selected, or i want to disable the edit text boxes when one radio button is selected. i really need help with this asap. On 3/25/2013 1:24 AM, Nikita Garg wrote: > i am implementing AHP using GUI. i have developed the code. >i am having problem with disabling the components. for example i >want to disable all the other radio buttons when one is selected, >or i want to disable the edit text boxes when one radio button is >selected. i really need help with this asap. > Just use the handle(s) of the UI control you want to disable and set its 'Enable' property The handles of all UI controls in the GUI are available for you. http://www.mathworks.com/help/matlab/ref/uicontrol_props.html#bqxoiky "Enable {on} | inactive | off Enable or disable the uicontrol. This property controls how uicontrols respond to mouse button clicks, including which callback routines execute." --Nasser ...

CheckBox in Column of JTable: Exception: java.lang.String cannot be cast to java.lang.Boolean
Hello, I have discovered a hidden error. My project was working for awhile, but then I started to get the below error. My error comes from the fact that I'm using a checkbox in a jtable, and I'm using the below "getColumnClass". Thank you, compile: run: Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean at javax.swing.JTable$BooleanRenderer.getTableCellRendererComponent(JTable.java:5412) at javax.swing.JTable.prepareRenderer(JTable.java:5735) at javax.swing.plaf.basic.BasicTableUI.paintCell(BasicTableUI.java:2114) at javax.swing.plaf.basic.BasicTableUI.paintCells(BasicTableUI.java:2016) at javax.swing.plaf.basic.BasicTableUI.paint(BasicTableUI.java:1812) at javax.swing.plaf.ComponentUI.update(ComponentUI.java:161) at javax.swing.JComponent.paintComponent(JComponent.java:778) at javax.swing.JComponent.paint(JComponent.java:1054) at javax.swing.JComponent.paintToOffscreen(JComponent.java:5221) at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1482) at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1413) at javax.swing.RepaintManager.paint(RepaintManager.java:1206) at javax.swing.JComponent._paintImmediately(JComponent.java:5169) at javax.swing.JComponent.paintImmediately(JComponent.java:4980) at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:770) at javax.swing.RepaintM...

java program in java GUI
folks I am writing a java GUI that calls other java programs i want to execute java command line options in back ground. I am using java exec command this is part of code Runtime.getRuntime().exec("/root/java/jdk1.5.0_06/bin/java /root/Desktop/project/SAXXMLHandler"); where i want to run SAXXMLHandler java file But i dont get any output thanks CSUIDL PROGRAMMEr wrote: > folks > I am writing a java GUI that calls other java programs > i want to execute java command line options in back ground. I am using > java exec command > this is part of code > > Runtime.getRuntime().exec("/root/java/jdk1.5.0_06/bin/java > /root/Desktop/project/SAXXMLHandler"); > > where i want to run SAXXMLHandler java file > > But i dont get any output What output did you expect? We have no clue as to what /root/Desktop/project/SAXXMLHandler is supposed to produce. How do you determine that there is no output? -- Nigel Wade, System Administrator, Space Plasma Physics Group, University of Leicester, Leicester, LE1 7RH, UK E-mail : nmw@ion.le.ac.uk Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555 well the output should say that Usuage: java parser as i am not passing any arguments In my command line i do not get anything thanks "CSUIDL PROGRAMMEr" <syedamjad_a@yahoo.com> wrote in message news:1143643407.154504.219230@e56g2000cwe.googlegroups.com... > well the output should say t...

Java GUI Swing Byte Text Area?
Hello, I've designed a GUI in java and I want one of the text areas to be of input bytes. Except JTextArea only inputs of type String and if I convert the string to byte arrray I lose precious and my answer doesn't make much sense in the end. Is there anything call JByteArea? I tried looking inthe Java API and found nothing or can anyone offer any other advice. Thank you "cryptogirl" <bobbie.burton@gmail.com> wrote in message news:1142093681.372596.290280@p10g2000cwp.googlegroups.com... > Hello, > > I've designed a GUI in java and I want one of the t...

JAVA TEXT AREA GUI problem #5
Is anybody know how to create a JAVA TEXT AREA with multiple color text in each line? (the setForegound seems can be used for single color for the whole text.) Thanks a lot. ...

Is there any corresponding C++ component for java.lang.reflect?
Hi all, I know C++ language does not support Java language's "reflect" mechanism. Is there any corresponding C++ component/library for java.lang.reflect? e.g., does Boost support "reflect"? Thanks! Best Regards, Xie, Bo xiebopublic@gmail.com wrote: > I know C++ language does not support Java language's "reflect" > mechanism. Is there any corresponding C++ component/library for > java.lang.reflect? e.g., does Boost support "reflect"? (1) No standard component. (2) Ask in forums on www.boost.org, but I strongly doubt it. V -- Pleas...

how to (right) align text within JTextField component...
i'm trying to right justify text within a JTextField component. what am i doing wrong...can someone point me in the right direction? import javax.swing.SwingConstants.*; displayText = new JTextField("0.",20); // this compiles but is left justified displayText = new JTextField.RIGHT("0.",20); // this does not compile "Scaramouche" wrote: > i'm trying to right justify text within a JTextField component. > what am i doing wrong... Misreading or not reading the API doc? > can someone point me in the right direction? setHorizontalAlignment()...

Include Java GUI components in figures in R13
Hi, Is there a possibility to include java gui classes, e.g. from swing, in a MATLAB R13 figure? Functions like javacomponent or get(f, 'javaframe') do not exist in MATLAB R13. Uwe ...

Error occurred during initialization of VM java/lang/NoClassDefFoundError: java/lang/Object (ant/tomcat/spring)
Hi, I've been trying to get Spring working with ant and tomcat. Ant was building just fine, but I came in today and tried to build it and got this: Error occurred during initialization of VM java/lang/NoClassDefFoundError: java/lang/Object ?!?! Makes no sense to me. There _is_ an older version of java installed on my machine; but JAVA_HOME and ANT_HOME are set to the correct paths, and <which java>and <java -version> produce the correct version. Any help would greatly alleviate my frustration! Thanks in advance... Courtney ...

Error occurred during initialization of VM java/lang/NoClassDefFoundError: java/lang/Object (ant/tomcat/spring)
Hi, I've been trying to get Spring working with ant and tomcat. Ant was building just fine, but I came in today and tried to build it and got this: Error occurred during initialization of VM java/lang/NoClassDefFoundError: java/lang/Object ?!?! Makes no sense to me. There _is_ an older version of java installed on my machine; but JAVA_HOME and ANT_HOME are set to the correct paths, and <which java>and <java -version> produce the correct version. Any help would greatly alleviate my frustration! Thanks in advance... Courtney ...

Final question (I hope): how to disable selection in text widget
I am very, very close to getting my app working on unix. Thanks to all who have helped me increase my skill with Tcl. I've got a borderless splash screen--a canvas w/ an embedded text window. The text window has URL's that I want to be "clickable", but I do not want other text to be "selectable" (either via a double click, or "click,shift click" after moving the mouse). I also need B1 and B1-Motion enabled so that one can drag the window--unless I can somehow get B1-Release to pass thru to a URL but have B1 & B1-Motion only apply to th...

Memory leaks when using Java GUI components in Matlab
I have noted that there are memory leaks in Matlab when Java GUI components WITH CALLBACKS are used. Java memory consumption can be traced for example with the Matlab monitoring tool by Joe Conti from the Matlab Central: http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=7127&objectType=file The reason for the memory leaks are apparently unused but referenced listeners set by matlab in the java components when the callback is set in matlab e.g. set(jh, 'xxxCallback', @foo) When e.g. a JButton is used then the memory leaks are hardly noticeable because the...

Make one GUI containing java and C++ componants ?
Hello, I have two application: one in java, which use awt and wing componants as a GUI. one in C++, which is a 3d engine, then it display in a window a 3D modele. I'm looking for a solution to combine these two interfaces in one containing the Java componant + the C++ window . Is there a way to manage with that? JNI doens t seem to be the good approach, it should be difficult to render the c++ output in a java component: moreover, interactions with the mouse are required in the ed engine... I heard about python, but I can t see the real advantage that can give me python. Any soluti...

Web resources about - JTextField - how to disable selecting text in this component? - comp.lang.java.gui

Fluent interface - Wikipedia, the free encyclopedia
. However, it can be detrimental to debugging, as a fluent chain constitutes a single statement for which debuggers may not allow setting up ...

George Dinwiddie's blog
Effective software development

James Shore: The Art of Agile
The Art of Agile SM James Shore "You influenced me to think in completely different ways, and to question traditional assumptions about everything ...

Index for the letter J : Java Glossary
Canadian Mind Products Java & Internet glossary : J words

Java™ SE Development Kit 7 Update 40 Bug Fixes
Java™ SE Development Kit 7 Update 40 Bug Fixes

Java Swing - Real's HowTo
Real's HowTo Custom Search Java Language String and Number Applet AWT Swing Environment IO Javascript interaction JDBC Thread Networking JSP ...

How to Use Formatted Text Fields (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing ...
This Swing Java Tutorial describes developing graphical user interfaces (GUIs) for applications and applets using Swing components

NetBeans IDE - Funcionalidades do GUI Builder Swing (Matisse)
... O GUI Builder se encarrega automaticamente do espaçamento e do alinhamento corretos. Clique em JLabels, JButtons, ButtonGroups, JTrees, JTextFields, ...

How to Use Password Fields (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components) ...
... developing graphical user interfaces (GUIs) for applications and applets using Swing components The JPasswordField class, a subclass of JTextField ...

NetBeans IDE - Swing GUI Builder (Matisse) Features
... The GUI builder automatically takes care of the correct spacing and alignment. Click into JLabels, JButtons, ButtonGroups, JTrees, JTextFields, ...

Resources last updated: 3/20/2016 5:48:24 PM