Click here to Skip to main content
15,867,885 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I m developing a calculator (for NIT Student) in Java.
I'm using netbeans 7.1.2 software.

In drag and drop for testing I drag and drop two JtextField ,
In one JTextField i will enter my marks (for Example 7.64).
Now in another JTextField (Grade for example B) should display (and it should be fixed and disabled so that no one can change it further) because Marks 7.64 corresponds to Grade B.... Similarly Marks 10 corresponds to Grade Ex(Excellent)..

**so how can i proceed i want to Enter my marks in one JTextField and in another JTextField Automatically Grade should display also Grade should be fixed (so that no one can change Grade) i mean Disable / Fixed .. U can see Grade but Can not alter or modify..
Posted
Updated 25-Mar-14 4:28am
v2

1 solution

I felt like adding a bit readability to your text.

You can disable a JTextField:

Java
JTextField oText = new JTextField();
oText.setEnable(false);


It will not take any input like that.

How to use TextFields[^]

EDIT: A bit tricky to figure - that function setEnable(boolean) is inherited from JComponent:

http://docs.oracle.com/javase/7/docs/api/javax/swing/JComponent.html#setEnabled(boolean)[^]



javax.swing.JTextField[^] @ API-Description on docs.oracle.com
 
Share this answer
 
v2
Comments
debasish deb 28-Mar-14 8:26am    
JTextField oText = new JTextField();
oText.setEnable(false);

this code is fine ,,,, but my question is how to convert marks to grade ... i mean in one JTextField i m entering marks and automatically it should be converted to Grade (Character)

because as for example i m entering marks 8.64 now 8,64 means Grade A ... so i need to convert this marks to Grade and Grade should come automatically(JFormattedTextField) When i enter Marks in JtextField ....

-------------------------- -------------------
JTextField(marks entered) JFormattedTextField (Grade comes automatically)
-------------------------- -------------------
TorstenH. 31-Mar-14 5:03am    
comparision is what you need - so use multiple if/else, or a switch-condition.
Shouldn't be the problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900