Results 1 to 15 of 15
- 05-18-2011, 08:01 AM #1
Member
- Join Date
- Jul 2010
- Posts
- 28
- Rep Power
- 0
prblem with JComboBox & awt.TextField
Hi,
I am getting a problem with JComboBox and awt.TextFiled. I have some JComboBox and awt.Textfields in the same column in my form. Now when I click on the JComboBox the dropdown list covers the TextField and it erase the TextField from the form. I know it can be solved by replacing awt.TextFields by JTextFields, but in my case I want the awt.TextField. please help me.
- 05-18-2011, 02:02 PM #2
Can you make a small simple example program that executes and demonstrates your problem and post it here
-
Why must you mix AWT and Swing components in the same GUI?
- 05-19-2011, 08:31 AM #4
Member
- Join Date
- Jul 2010
- Posts
- 28
- Rep Power
- 0
At the very begining I used swing JTextField and DocumentListener to achieve my goal. But with the documentlistener, sometimes it works and sometimes not. sometimes textfields were hang also.Then I switch to awt.textfield and textlistener, and now it is working fine. But the new problem is arise as I mention above.
- 05-19-2011, 08:41 AM #5
Member
- Join Date
- Jul 2010
- Posts
- 28
- Rep Power
- 0
- 05-19-2011, 09:08 AM #6
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,561
- Rep Power
- 11
You should not post a huge lump of code. One of the reasons for writing a small example of the problem is that it may well help you identify what is causing the problem. (rather than just knowing some symptoms that occur in a particular context). So if your small example behaves as expected then you have to change it to more resemble the code that is giving rise to the problem. Step by step, until you have identified what is significant in your original code.
-----
I notice in Oracle's article Mixing Heavyweight and Lightweight Components that they say "As of the JDK 6 Update 12 and JDK 7 build 19 releases, it is now possible to seamlessly mix heavyweight and lightweight components within the same container." Others here might like to comment as the "don't mix swing and awt" advice is often given.
In any case there seems something wrong with your motivation for mixing the two in the first place.
If there was a problem with your use of JTextField and DocumentListener, then that would seem to be the problem that should be addressed, rather than this mixing of light and heavy weight components.At the very begining I used swing JTextField and DocumentListener to achieve my goal. But with the documentlistener, sometimes it works and sometimes not. sometimes textfields were hang also.Then I switch to awt.textfield and textlistener...
- 05-20-2011, 10:13 AM #7
Member
- Join Date
- Jul 2010
- Posts
- 28
- Rep Power
- 0
Hi all again
Now I switch back to Swing JTextField and Documentlistener. When I write anything to the first JtextField I get the following error-
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(Num berFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:493)
at java.lang.Integer.parseInt(Integer.java:514)
at standared.removeUpdate(trans_standared.java:4154)
at javax.swing.text.AbstractDocument.fireRemoveUpdate (AbstractDocument.java:260)
at javax.swing.text.AbstractDocument.handleRemove(Abs tractDocument.java:625)
at javax.swing.text.AbstractDocument.remove(AbstractD ocument.java:593)
at javax.swing.text.AbstractDocument.replace(Abstract Document.java:669)
at javax.swing.text.JTextComponent.setText(JTextCompo nent.java:1707)
at standared.load_no_full_sheets(trans_standared.java :1580)
at standared.focusGained(trans_standared.java:2876)
at java.awt.AWTEventMulticaster.focusGained(AWTEventM ulticaster.java:220)
at java.awt.Component.processFocusEvent(Component.jav a:5990)
at java.awt.Component.processEvent(Component.java:585 7)
at java.awt.Container.processEvent(Container.java:210 5)
at java.awt.Component.dispatchEventImpl(Component.jav a:4462)
at java.awt.Container.dispatchEventImpl(Container.jav a:2163)
at java.awt.Component.dispatchEvent(Component.java:42 88)
at java.awt.KeyboardFocusManager.redispatchEvent(Keyb oardFocusManager.java:1881)
at java.awt.DefaultKeyboardFocusManager.typeAheadAsse rtions(DefaultKeyboardFocusManager.java:936)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent (DefaultKeyboardFocusManager.java:551)
at java.awt.Component.dispatchEventImpl(Component.jav a:4332)
at java.awt.Container.dispatchEventImpl(Container.jav a:2163)
at java.awt.Component.dispatchEvent(Component.java:42 88)
at java.awt.EventQueue.dispatchEvent(EventQueue.java: 604)
at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:275)
at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:200)
at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:190)
at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:185)
at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:177)
at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:138)
I can guess that it is from the large calculations of the code. But I fail to detect the error.......
- 05-20-2011, 10:35 AM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,604
- Blog Entries
- 7
- Rep Power
- 17
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 05-20-2011, 10:53 AM #9
Member
- Join Date
- Jul 2010
- Posts
- 28
- Rep Power
- 0
There is a statement in my code like
txtno_of_full_sheets_required.setText(Integer.toSt ring(cal1));
and errors start from here. the statement can't be executed and the textfield remain emty. In the further portion of the code, calculations use the data from this textfield and find an empty string.
If I insert a statement like
System.out.println(cal1); before the setText statement it prints the correct value.......means cal1 is not empty.
I dont know why setText() is not working.............
- 05-20-2011, 01:38 PM #10
Are you sure you are looking at the right place in your code?at java.lang.Integer.parseInt(Integer.java:514)
The error message refers to a call to the parseInt() method not to toString()
- 05-20-2011, 03:33 PM #11
Member
- Join Date
- Jul 2010
- Posts
- 28
- Rep Power
- 0
- 05-20-2011, 03:34 PM #12
Member
- Join Date
- Jul 2010
- Posts
- 28
- Rep Power
- 0
I found that errors are generated from the DocumentListener. I just remove everything from the removeUpdate() and my code starts to work.
I guess that the setText() method works in two steps
1. delete the data from the textfield
2. write the new data
I guess errors are generated at the time of deleting the data.
Now the issue is my textfields dont respond when I delete value from there. But I want that also.
- 05-20-2011, 03:50 PM #13
Without seeing the code and having a working program to debug, there's not much we can do to help.
- 05-21-2011, 09:47 AM #14
Member
- Join Date
- Jul 2010
- Posts
- 28
- Rep Power
- 0
Last edited by DarrylBurke; 05-21-2011 at 11:31 AM. Reason: Removed email address
- 05-21-2011, 11:31 AM #15
Similar Threads
-
Won't set to textfield
By Steffers in forum New To JavaReplies: 7Last Post: 11-04-2010, 02:32 PM -
Activate JComboBox 1 when object is selected in JComboBox 2...
By bahumbaba in forum AWT / SwingReplies: 2Last Post: 12-10-2009, 01:58 PM -
TextField Example
By Java Tip in forum SWTReplies: 0Last Post: 07-25-2008, 02:21 PM -
Prblem in Prepared Statement
By haneeshrawther in forum JDBCReplies: 2Last Post: 04-25-2008, 09:49 AM -
JSP - getting value from a textfield
By Java Tip in forum Java TipReplies: 0Last Post: 12-01-2007, 08:58 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks