Only 48 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to make JTextField editable?  RSS feed

 
J.B. Park
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Java/netbeans People!

I'm having a hard time finding out the way to make JTextField editable.
In what circumstances it can be disabled to write? [even the text in the field can't be selected, not to mention being uneditable :-(]
I did the followings to make it editable.

1. In its Properties panel(frame or whatever), checked the "editable" item.
2. In the code I made it run the code below,

Is it related with the properties of the control(JTextField)'s surrounding panel, or even the largest containing frame?

Thank you very much all,

<a newbie in using Netbeans>
 
Campbell Ritchie
Sheriff
Posts: 53720
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I added code tags; always use them. Don't they make your post look better
Does this Java Tutorials section about text fields help?
 
J.B. Park
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the reply. However, it(Oracle manual) didn't help, though.
In fact, I created another project to test the JTextField editable property operation.
The result is "it worked very normal as I expected." And I compared the two JTextFields(problematic one and the later version of working perfect version) property by property.
Here I attached the fine version. I bet the wrong JTextField has the same value for each property. Phew,...
(Only the caret position was different. The other JTextField has '0' for it.

I appreciate your effort anyway.
jtextfield_prop_all.png
[Thumbnail for jtextfield_prop_all.png]
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JTextField are editable by default. You don't need to do anything special. Just create one by new JTextField();
Non Editable -> User cannot change the current value. However, he can still select/highlight it
Disabled -> No value changes. no select/highlight

If you are at a beginners stage, I would recommend dropping the DnD type UI builders and start hand coding
 
J.B. Park
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know if I'm a newbie really. Anyway, Here is one more thing on my problematic project--

The JTextField displays a field value from a selected row in a JTable.

The JTable is made sortable by clicking its column heading. To allow the users be able to sort the JTable, the JTable's 'AutoCreateColumnsFromModel' property is set to true(=checked).

To make the selected row maintain its status of being selected(highlighted) and visible through all the sorting practices, I thank Oscar's solution shown in the
http://stackoverflow.com/questions/2075396/correctly-getting-data-from-a-sorted-jtable

and I referred to the Rob's suggestion from the following topic--
http://www.coderanch.com/t/623472/GUI/java/JTable-selected-row-visible-sort

Well, let me remove all those parts, that have added while I make sorting and selection things work correctly, one bye one and check if the JTextField is editable as is supposed to be.

Thank you for your time always!
 
Charles Sexton
Ranch Hand
Posts: 273
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A tip since your new.

I have found myself in the past that could be easily answered through the java api.

http://docs.oracle.com/javase/7/docs/api/javax/swing/text/JTextComponent.html

This class is the superclass to jTextField which allows you to set the JTextField editable to true or false. By default it is true so you can naturally be able to just create one and start typing away in your new component. However a person can set editable to false until a certain point in the application and then set editable back to true which can be beneficial depending on the design aspect of the application. But always remember that the java api is your best friend if you are learning and in general developing in java. I would also not recommend using the Netbeans drag and drop gui builder. You need practice and gui building by writing can be a good way to learn many important aspects such as class inheritance and logic.
 
J.B. Park
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After all this trouble, I create the project from scratch. Now it working as I expect (JTextField is editable!)
Thank you for all the advices so far.

JB.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!