Results 1 to 15 of 15
  1. #1
    hitesh is offline Member
    Join Date
    Jul 2010
    Posts
    28
    Rep Power
    0

    Exclamation 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.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,318
    Rep Power
    25

    Default

    Can you make a small simple example program that executes and demonstrates your problem and post it here

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  4. #4
    hitesh is offline Member
    Join Date
    Jul 2010
    Posts
    28
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    Why must you mix AWT and Swing components in the same GUI?
    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.

  5. #5
    hitesh is offline Member
    Join Date
    Jul 2010
    Posts
    28
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    Can you make a small simple example program that executes and demonstrates your problem and post it here
    Hi Norm
    I am shocked when I create a small program with same situation. Because it is working fine. So I have to post my original code. But it is too big and too ugly. what should I do now?

  6. #6
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Quote Originally Posted by hitesh View Post
    Hi Norm
    I am shocked when I create a small program with same situation. Because it is working fine. So I have to post my original code. But it is too big and too ugly. what should I do now?
    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.

    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...
    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.

  7. #7
    hitesh is offline Member
    Join Date
    Jul 2010
    Posts
    28
    Rep Power
    0

    Default

    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.......

  8. #8
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,447
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by hitesh View Post
    Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: ""
    at java.lang.NumberFormatException.forInputString(Num berFormatException.java:65)
    An empty String obviously doesn't represent a number; adjust your code so that it doesn't throw an exception, e.g.

    Java Code:
    try {
       ...
    }
    catch (NumberFormatException nfe) { 
       // not a number in the field
    }
    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    hitesh is offline Member
    Join Date
    Jul 2010
    Posts
    28
    Rep Power
    0

    Default

    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.............

  10. #10
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,318
    Rep Power
    25

    Default

    at java.lang.Integer.parseInt(Integer.java:514)
    Are you sure you are looking at the right place in your code?
    The error message refers to a call to the parseInt() method not to toString()

  11. #11
    hitesh is offline Member
    Join Date
    Jul 2010
    Posts
    28
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    Are you sure you are looking at the right place in your code?
    The error message refers to a call to the parseInt() method not to toString()
    Yes I am sure. One statement trying to parse the content of the txtno_of_full_sheets_required textfield as int. But the txtno_of_full_sheets_required is empty since setText() is not worked. Problem starts from the setText().

  12. #12
    hitesh is offline Member
    Join Date
    Jul 2010
    Posts
    28
    Rep Power
    0

    Default

    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.

  13. #13
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,318
    Rep Power
    25

    Default

    Without seeing the code and having a working program to debug, there's not much we can do to help.

  14. #14
    hitesh is offline Member
    Join Date
    Jul 2010
    Posts
    28
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    Without seeing the code and having a working program to debug, there's not much we can do to help.
    can I have your email-id. i would like to send my code to your email.
    my email id is "Moderator edit: removed"
    please send me a test mail.

    Note: I have no problem to paste my code in the forum. But since it is too big I am not doing that.
    Last edited by DarrylBurke; 05-21-2011 at 11:31 AM. Reason: Removed email address

  15. #15
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,196
    Rep Power
    19

Similar Threads

  1. Won't set to textfield
    By Steffers in forum New To Java
    Replies: 7
    Last Post: 11-04-2010, 02:32 PM
  2. Replies: 2
    Last Post: 12-10-2009, 01:58 PM
  3. TextField Example
    By Java Tip in forum SWT
    Replies: 0
    Last Post: 07-25-2008, 02:21 PM
  4. Prblem in Prepared Statement
    By haneeshrawther in forum JDBC
    Replies: 2
    Last Post: 04-25-2008, 09:49 AM
  5. JSP - getting value from a textfield
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-01-2007, 08:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •