Problems in JTextField

Hi, we have seen a strange behaviour in JTextField. Our development tool is Visual Age for Java 3.5.2. We are trying to enter "hello� (alt 0137)" but another different character is shown "hello�". It makes nonsense because you can retrieve the right string with getText in code
We think that is a JRE problem, but we really don�t know what�s wrong.
Can anybody help us?
Thanks in advance!

just to keep this question alive!

Similar Messages

  • Memory problem with JTextFields

    Hello,
    I have a wierd problem with JTextField and the memory.
    I need to fill a JPanel with different Components (including JTextFields), then do some calculation, remove the Components and filling the JPanel again.
    When i so this too often my i get an OutOfMemory Exception. I narrowed to problem down and wrote a small sample program to demonstrate the problem.
    When i call the method doIT (where the Panel is repeatedly filled) from the main-function everything works fine, but when it is called as a result from the GUI-Button-Event the memory for the JTextFields is not freed (even the call of the Garbage collector changes nothing)
    When i only use JButtons to fill the Panel everything works fine.
    Has anyone an idea why this problem occurs and how i can work around it?
    [Edit] I tested it whith java 1.5.0_06, 1.5.0_11, 1.6.0_02
    Thanks
    Marc
    import java.awt.Frame;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.lang.management.ManagementFactory;
    import java.lang.management.MemoryUsage;
    import javax.swing.JButton;
    import javax.swing.JDialog;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    public class MemoryTestDLG extends JDialog {
         public MemoryTestDLG(Frame owner) {
              // create Dialog with one Button that calls the testMethod
              super(owner);
              JButton b = new JButton("doIT ...");
              b.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e) {
                        doIT();
                        setVisible(false);
              getContentPane().add(b);
              pack();
         public void doIT() {
              // Testmethod that fills a JPanel 20 times with Components and clears it
              // again
              JPanel p = new JPanel();
              long memUse1 = 0;
              long memUse2 = 0;
              long memUseTemp = 0;
              for (int count = 0; count < 20; count++) {
                   // Clear the panel
                   p.removeAll();
                   // Get memory usage before the task
                   Runtime.getRuntime().gc();
                   memUse1 = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage()
                             .getUsed();
                   // Fill Panel with components
                   for (int i = 0; i < 200; i++) {
                        // The Buttons seem to be released without any problem
                        p.add(new JButton("test" + Math.random()));
                        // JTextFields are not released when used from the dialog.
                        p.add(new JTextField("test " + Math.random()));
                   // get memory usage after the task
                   Runtime.getRuntime().gc();
                   memUseTemp = memUse2;
                   memUse2 = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage()
                             .getUsed();
                   // print Memory results
                   System.out.println("Memory Usage: " + f(memUse1) + "   ->"
                             + f(memUse2) + " [ Used:" + f(memUse2 - memUse1)
                             + " ] [ Freed: " + f(memUseTemp - memUse1) + "]");
         public String f(long m) // formats the output
              String s = "" + m;
              while (s.length() < 8)
                   s = " " + s;
              return s;
         public static void main(String[] args) {
              MemoryTestDLG d = new MemoryTestDLG(null);
              System.out
                        .println("------------------ Direct Call (all is OK) -------------------");
              d.doIT(); // Memory is freed with every call to JPanel.removeAll()
              System.out
                        .println("------------ Call from Dialog (memory is not freed) -------------");
              // The Memory keeps blocked
              d.setModal(true);
              d.setVisible(true);
              System.exit(0);
    }Message was edited by:
    marcvomorc

    Thank you for your answer,
    In this sample the programm does not run out of memory. But when you look at the output you see, that in the first run (direct call) the memory ist freed immediately when tha panel is cleared but in the second run (from the Button) the memory usage is getting bigger and bigger. Wenn you change the number of components to 2000 (4000)
    // Fill Panel with components
            for (int i = 0; i < 2000; i++) {
                // The Buttons seem to be released without any problem
    //... ...and use the default memory settings (69mb heap) the programm runns out of memory.
    I get the following output:
    ------------------ Direct Call (all is OK) -------------------
    Memory Usage:   445504   -> 8121016 [ Used: 7675512 ] [ Freed:  -445504]
    Memory Usage:   617352   -> 8114336 [ Used: 7496984 ] [ Freed:  7503664]
    Memory Usage:   810488   -> 8491768 [ Used: 7681280 ] [ Freed:  7303848]
    Memory Usage:   943704   -> 8114976 [ Used: 7171272 ] [ Freed:  7548064]
    Memory Usage:   836760   -> 8505072 [ Used: 7668312 ] [ Freed:  7278216]
    Memory Usage:   978352   -> 8114784 [ Used: 7136432 ] [ Freed:  7526720]
    Memory Usage:   835552   -> 8498288 [ Used: 7662736 ] [ Freed:  7279232]
    Memory Usage:   977096   -> 8114312 [ Used: 7137216 ] [ Freed:  7521192]
    Memory Usage:   835640   -> 8498376 [ Used: 7662736 ] [ Freed:  7278672]
    Memory Usage:   977296   -> 8115000 [ Used: 7137704 ] [ Freed:  7521080]
    Memory Usage:   835392   -> 8504872 [ Used: 7669480 ] [ Freed:  7279608]
    Memory Usage:   976968   -> 8115192 [ Used: 7138224 ] [ Freed:  7527904]
    Memory Usage:   836224   -> 8501624 [ Used: 7665400 ] [ Freed:  7278968]
    Memory Usage:   977840   -> 8115120 [ Used: 7137280 ] [ Freed:  7523784]
    Memory Usage:   835664   -> 8498256 [ Used: 7662592 ] [ Freed:  7279456]
    Memory Usage:   976856   -> 8114384 [ Used: 7137528 ] [ Freed:  7521400]
    Memory Usage:   835784   -> 8502848 [ Used: 7667064 ] [ Freed:  7278600]
    Memory Usage:   977360   -> 8114592 [ Used: 7137232 ] [ Freed:  7525488]
    Memory Usage:   835496   -> 8502720 [ Used: 7667224 ] [ Freed:  7279096]
    Memory Usage:   976440   -> 8115128 [ Used: 7138688 ] [ Freed:  7526280]
    ------------ Call from Dialog (memory is not freed) -------------
    Memory Usage:   866504   -> 8784320 [ Used: 7917816 ] [ Freed:  -866504]
    Memory Usage:  7480760   ->14631152 [ Used: 7150392 ] [ Freed:  1303560]
    Memory Usage: 14245264   ->22127104 [ Used: 7881840 ] [ Freed:   385888]
    Memory Usage: 19302896   ->27190744 [ Used: 7887848 ] [ Freed:  2824208]
    Memory Usage: 27190744   ->35073944 [ Used: 7883200 ] [ Freed:        0]
    Memory Usage: 31856624   ->39740176 [ Used: 7883552 ] [ Freed:  3217320]
    Memory Usage: 39740176   ->47623040 [ Used: 7882864 ] [ Freed:        0]
    Memory Usage: 44410480   ->52293864 [ Used: 7883384 ] [ Freed:  3212560]
    Memory Usage: 52293864   ->58569304 [ Used: 6275440 ] [ Freed:        0]
    Memory Usage: 58569304   ->64846400 [ Used: 6277096 ] [ Freed:        0]
    Exception occurred during event dispatching:
    java.lang.OutOfMemoryError: Java heap spacewhen I outcomment the adding of the JButtons the amount of freed memory is 0 in the second run. So my guess is, that there is a problem with freeing the memory for the JTextFields.
    Memory Usage:   447832   -> 6509960 [ Used: 6062128 ] [ Freed:  6332768]
    Memory Usage:   722776   -> 6785632 [ Used: 6062856 ] [ Freed:  5787184]
    ------------ Call from Dialog (memory is not freed) -------------
    Memory Usage:   468880   -> 6770240 [ Used: 6301360 ] [ Freed:  -468880]
    Memory Usage:  6770240   ->13016264 [ Used: 6246024 ] [ Freed:        0]
    Memory Usage: 13016264   ->19297080 [ Used: 6280816 ] [ Freed:        0]
    Memory Usage: 19297080   ->25570152 [ Used: 6273072 ] [ Freed:        0]
    Memory Usage: 25570152   ->31849160 [ Used: 6279008 ] [ Freed:        0]
    Memory Usage: 31849160   ->38124368 [ Used: 6275208 ] [ Freed:        0]
    Memory Usage: 38124368   ->44402072 [ Used: 6277704 ] [ Freed:        0]
    Memory Usage: 44402072   ->50677928 [ Used: 6275856 ] [ Freed:        0]
    Memory Usage: 50677928   ->56955880 [ Used: 6277952 ] [ Freed:        0]
    Memory Usage: 56955880   ->63232152 [ Used: 6276272 ] [ Freed:        0]
    Exception occurred during event dispatching:
    java.lang.OutOfMemoryError: Java heap spaceAdditionally the JPanel I am using is not displayed on the screen. It stays invisible the whole time, but i cannot work around that, because the calculation is depending on the values being in components on the JPanel)
    Marc

  • Problem updating JTextField

    Hi,
    I have written a program with a main class and two instances of an inner class. The main class extends JFrame and is the container that holds six JTextFields. In the main class is a JButton called "testme". When the user clicks on the "testme" button I want to update the JTextFields. My problem is that I am confused about where the event handling should take place. Is it proper to keep the "testme" button in the main class and update the panels in the inner class or do I need to have all of the event handling at the inner class level? I really want to understand the conceptual issues as well as the code.
    Thanks,
    Steve
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    class TestButton extends JFrame implements ActionListener {     AddButtons leftPanel, rightPanel;
         JTextArea msgout;
         JButton buttonTest;
         TestButton() {
              super("This is a JFrame");
                    setSize(500, 200);  // width, height
                    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);     
                  JPanel pane = new JPanel();     // create empty space          pane.setBorder(BorderFactory.createEmptyBorder(30, 30, 10, 30));
              JButton buttonTest = new JButton("TestMe");     
                 buttonTest.addActionListener(this);
              msgout = new JTextArea( 8, 40 ); // instance TextArea
                    String[] leftlabels = {"left1", "left2", "left3"};          leftPanel = new AddButtons(this, leftlabels);     
                 String[] rightlabels = {"right1", "right2", "right3"};          rightPanel = new AddButtons(this, rightlabels);          
                   GridLayout grid = new GridLayout(1, 3, 5, 15);
                    pane.setLayout(grid);
              pane.add(buttonTest);
              pane.add(msgout);
              pane.add(leftPanel);
              pane.add(rightPanel);
              msgout.append("Successful");
              setContentPane(pane);
              setVisible(true);
    public void actionPerformed(ActionEvent evt) {     
         String command = evt.getActionCommand();               if (command.equals("TestMe")){                    msgout.append("\nSuccessful");
    public static void main(String[] arguments) {
            JFrame frame = new TestButton();
            frame.show();
    class AddButtons extends JPanel implements ActionListener {     TestButton frame; // instance variable of class TestButton     JTextField[] setting = new JTextField[3];  // instance variable     private int numClicks = 0;
            AddButtons (TestButton parent, String[] label) {     // 1   parent declared here makes it public
              JLabel textUpdate = new JLabel();
              frame = parent;      // associates the classes
                 GridLayout grid = new GridLayout(3, 1, 5, 15);
                  setLayout(grid);
              for (int i = 0; i < 3; i++) {
                         setting[i] = new JTextField("0");                       setting.addActionListener(this);               JLabel settingLabel = new JLabel(label[i], JLabel.RIGHT);
                   add(settingLabel);
                   add(setting[i]);
    //This is where I thought I might capture the "testme" event     
    public void actionPerformed(ActionEvent evt) {
              String command = evt.getActionCommand();               if (command.equals("TestMe")){
              setting[2].setText("2003");               }          }

    This article should help you out:
    http://www-106.ibm.com/developerworks/java/library/j-jtable/index.html?dwzone=java

  • Problems with JTextField

    I'm having a very odd problem with a JTextField. I've got on which I'm using to enter barcodes from a barcode scanner. When I type the barcode in manual it works fine, but when I scan the barcode in I get ?'s in random positions. If I scan the barcode in more than once I get the ?'s in different places.
    There is nothing wrong with the scanner because I can quite happily scan barcodes directly into a text document. Any thoughts?

    - As suggested earlier you should test the scanner
    with other text components... JTextArea for exampleI tried a JTextArea and a JTextPane last night an both had the same problem. I also tried using a KeyListener. This printed out the ?'s when I used the getKeyChar() method of KeyEvent but printed some very odd (large 10 digit) numbers when I used the getKeyCode() method.
    - Determine if the characters encoded in the bar-code
    can be displayed with the font that is being used with
    the text fields.Mmmm, not sure how to do this.
    - Determine if the symbology you are trying to de-code
    is configured correctly (and the bar-code reader is
    set up to read it correctly) Be aware that some codes
    have leading "guard" characters which the reader may
    not be removing (this has to be set in the scanner
    itself)The is no configuration for the scanner that I know of. Not sure what these "guard" characters are - maybe they are the ones I'm getting on the KeyListener.
    Built a version of the GUI quickly in Visual Basic 6 (grrrrr) and when I entered numbers into a TextBox there were no problems. Could this be a Java bug?
    Thanks to everyone for your help so far. Any more thoughts?

  • Weird problem in JTextFields ..!!

    Hi thr,
    It seems a buffer is held within , when a text in unicode is entered
    in the JTextFields,
    Following is the code snippet from the Class which overrides PlainDocument class
    and attached to a JTextfield
    public void insertString(int r_iOffset, String r_stNewText,
    AttributeSet r_objAttr) throws BadLocationException
         System.out.println( r_stNewText );
    int Entered = (int) r_stNewText.toCharArray()[ r_stNewText.length()-1 ] ;
    if (Entered > 255)
    r_stNewText = "";
    r_objAttr = null;
    return;
    // Further processing for ascii text
    Assuming two keyboard layouts are setup in the OS , one English and other Japanese.
    When the textfield is in focus , the OS keyboard layout is changed to japanese
    by alt+~ keys , and all the japanese keys input are succesfully blocked, but when keys "\\"
    is entered , the hidden buffered string is displayed in the Jtextfield, and all the
    keys therafter has only ascii values !! , and there by bypassing the constraint.
    When System.out is used to debug , each and every character , we can see the new string
    passed , is continually is increasing with evry new charecter , even though we make it
    as empty string.
    can somebody comment this issue ?
    cheers,
    thanks (ver much ) in advance.

    Any suggestions , at least ?

  • Problem matching JTextField input to an item in a JList box

    Hello,
    I am trying to read the user's input in a text field and take the user to a match in a list box located underneath the textfield. To do that I have implemented the following code:
    m_pathwayNameTextField.addKeyListener(new KeyAdapter() {
    public void keyTyped(KeyEvent e) {
    m_pathwayNameTextField_KeyTyped(e);
    private void m_pathwayNameTextField_KeyTyped(KeyEvent e) {
    if (e.getID() == KeyEvent.KEY_TYPED) {
    String prefix = m_pathwayNameTextField.getText();
    char c = e.getKeyChar();
    if (e.getKeyChar() >= KeyEvent.VK_SPACE && e.getKeyCode() < 127) {
    prefix = prefix + e.getKeyChar();
    int position = m_pathwayNamesList.getNextMatch(prefix, 0,
    Position.Bias.Forward);
    if (position != -1) {
    m_pathwayNamesList.ensureIndexIsVisible(position);
    Although the above kind of works, it still has some problems. The first is that if I press a "backspace" character, it won't try to match any results. Also, if I highlight the whole text in the textfield and press a letter, it won't attempt to match either. The reason for the later is that the textfield at that time is not blank and so prefix becomes the textfield plus the newly entered letter, whereas it should be the newly entered letter.
    Any help on this is highly appreciated.
    Thanks.

    The best way to do this is to use a DocumentListener instead of a KeyListener. When the DocumentEvent is fired the document has already been updated and you can just use getText() to get the contents of the Document. No need to play around with backspace characters.

  • Problem with JTextFields being very small

    public void AddAccount()
                   //internal frame when a new account is being made
                   JInternalFrame frame = new JInternalFrame( "Add Account", true, true, true, true);
                                  JPanel panel = new JPanel();     //creates a panel to house labels and fields
                                                                JLabel accountNumber = new JLabel("Account Number");
                                  accountNumbers = new JTextField();
                                  JLabel Balance = new JLabel("Balance");
                                  Bal = new JTextField();
                                  JLabel interestRate = new JLabel("Interest Rate");
                                  intRate = new JTextField();
                                  submit = new JButton("Submit");
                                  //Text area display
                                  JPanel DisplayPanel = new JPanel();
                                  JTextArea Display = new JTextArea(25, 25);
                                  Display.setEditable(false);
                                  DisplayPanel.add(Display);
                                  panel.add(accountNumber);
                                  panel.add(accountNumbers);
                                  panel.add(Balance);
                                  panel.add(Bal);
                                  panel.add(interestRate);
                                  panel.add(intRate);
                                  panel.add(submit);
                                  frame.setLayout(new BorderLayout());
                                  frame.add(panel, BorderLayout.NORTH);
                                  frame.add( DisplayPanel, BorderLayout.CENTER);
                                  frame.setVisible(true);
                                  frame.setSize(640,480);
                                  frame.pack();
                                  appDesktop.add(frame);
              }This code opens the new frame and displays the labels and the button fine. The Center part of the layout is fine as well. I cannot figure out how to get the JTextfields bigger.
    Message was edited by:
    UofL17

    In the future Swing related questions should be posted in the Swing forum.
    . I cannot figure out how to get the JTextfields biggerRead the JTextField API. There is more than one constructor.
    If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program (SSCCE) that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
    And don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags so the code retains its original formatting.

  • JTextField Problem

    Hi
    I have the following problem with JTextField:
    I have a class which builds up an array of JTextFields.I have another class which takes the array and lays the JTextFields out on a JFrame. It also controls the size of the JTextFields. Sometimes the text is longer than the size of the TextField and by looking at it the user dose not know if there is more text. The problem is he cannot see that the text is truncated ie no ... at the end of the text.
    I have to use JTextfields as it would take too much code change to use anything else.
    Any one any suggestions
    Thanks
    B

    Hi,
    I hope having understood your problem.
    I assume there that you know the string written in each textfield.
    You can construct your textfields such as :
    JTextField jT = new JTextField("MyKnownText");Then, you can do the following :
    public class Test
        public static main(String[] args)
            // Your main
            TextField[] array = // ... Your array of textfields.
            setSameComponentSize(Arrays.asList(array));
         * Resize with the same maximum size all specified components.
         * @param sComponents The components to be resized
        public static void setSameComponentSize(List sComponents)
            // compute the maximum dimension
            // and get only components
            // The dimension to which resize all components.
            Dimension lMaxDim = new Dimension();
            // The dimension to compare.
            Dimension lCompSize;
            // The component to resize.
            JComponent lComp;
            for (Iterator lIter = sComponents.iterator(); lIter.hasNext();)
                lComp = (JComponent) lIter.next();
                if (lComp != null)
                    lCompSize = lComp.getPreferredSize();
                    if (lCompSize.width > lMaxDim.width)
                        lMaxDim.width = lCompSize.width;
                    if (lCompSize.height > lMaxDim.height)
                        lMaxDim.height = lCompSize.height;
            // set the same size for all components
            for (Iterator lIter = sComponents.iterator(); lIter.hasNext();)
                lComp = (JComponent) lIter.next();
                if (lComp != null)
                    lComp.setPreferredSize(lMaxDim);
                    lComp.setMaximumSize(lMaxDim);
                    lComp.setMinimumSize(lMaxDim);
    }This code will set all the textfields to the same size that will be the maximum preferred size of the textfields.
    I do not test it but I hope it will be helpful for you.
    Stephane.

  • Can not focus or edit on JTextField on SuSe Linux 9.1

    Hi,
    I am trying to debug a strange problem with JTextField on SuSe Linux 9.1.
    The problem is that the mouse click can not gain focus to the JTextField
    in a very high frequency. Once problem occurs, the keyboard tab also
    does not work. The problem does not happen all the time.
    I wrote a simple event listener that dump out events that confirm that
    the TextField got the mouse click event.
    We are using JDK1.4.2_05.
    The same piece of code works fine with Windows XP and RedHat.
    I would greately appreciated if you have any suggestion to debug this
    issue.
    Thanks,

    The first thing to do is identify which of the two rows with the same key value are correctly referenced by rows in other tables.  If all referencing rows relate to only one of the errant pair then you can insert the non-key values from the other
    one into a new row, and then delete the original 'bad' row.  If you find that there are rows in referencing tables which relate to each of the errant pair, then, after copying the non-key values from one into a new row and deleting the 'bad'  original,
    you'll need to change the foreign key values in those rows in any referencing tables which related to the 'bad'  original to the value of the primary key in its replacement row.  You'll need to delete the relationship before doing any of this of
    course.
    Once you've done the above I'd then be inclined to copy the table to a new one under a different name, delete the original table, rename the copy to the original name, and then re-create the enforced relationship.  Finally, compact and repair the database.
    Ken Sheridan, Stafford, England

  • Set images on to JTextPane from JTextField or JTextPane using ":)"

    Hi,
    Please see my problem
    jtf = JTextField();
    ae = ActionEvent
    jta = JTextPane();
         if(ae.getSource() == jtf)
                   String Sticon = jtf.getText();
                   //jta.setText(Sticon);
                   System.out.println(Sticon);
                   if(Sticon == ":)" || Sticon.equals(":)"))
                        jta.insertIcon(new ImageIcon("07.gif"));
                        System.out.println("inside sticon");
                   else
                        jta.setText(Sticon);
                   jtf.setText("");
    Help please
    Thanks

    Do not use a test like if (Sticon == ":)")... for a String you always have to use the equals()[b] method.

  • JtextField.setText()

    im having problem with JTextField.setText()... let say i have a vector containing multiple strings and i wanna set the text of a jtextfield with one of my vector's element i do:
    JTextField.setText((String)Vector.firstElement());
    but how come in my jtextfield the new string isnt showing... do i need to repaint my whole frame????
    thx

    You don't supply enough info to know the problem. You shouldn't have to repaint. Where is your JTextField Defined. If you defined inside a constructor or method, you can get the results you are having.

  • Problem wit JOptionPane.showMessageDialog

    I'm not getting where is the problem here,
    JTextField = AlteKarte,jtf3;
    jtf3.addFocusListener(new FocusListener() {
    public void focusGained(FocusEvent e) {
    public void focusLost(FocusEvent e) {
    if (!e.isTemporary() && isEnabled() ) {
    String Alte = AlteKarte.getText();
    String FoneNum = jtf3.getText();
    if (Alte.length() != 0 ){
    if(Alte.equals("123") != FoneNum.equals("123")) {
    JOptionPane optionPane = new JOptionPane();
    int answer =((Integer)optionPane.getValue()).intValue();
    JOptionPane.showMessageDialog(MainEPOS.frame,"Geben Sie bitte gultige Karten-Seriennummer an.","Fehler",JOptionPane.WARNING_MESSAGE,null);
    if(answer == JOptionPane.OK_OPTION || answer == JOptionPane.CLOSED_OPTION){
    jtf3.requestFocus(true);
    [\code ]
    i'm getting java.lang.ClassCastException at line int answer =((Integer)optionPane.getValue()).intValue();
    [\code]

    i have made it this way :-
             jtf3.addFocusListener(new FocusListener() {
                  public void focusGained(FocusEvent e) {
                  public void focusLost(FocusEvent e) {
                    if (!e.isTemporary() && isEnabled() ) {
                      String Alte = AlteKarte.getText();
                      String FoneNum = jtf3.getText();
                      if (Alte.length() != 0 ){
                           if(Alte.equals("123")  != FoneNum.equals("123")) {
                       JOptionPane optionPane = new JOptionPane();
                       Object[] options = {"OK"};
                       int answer =   JOptionPane.showOptionDialog(MainEPOS.frame,"Geben Sie bitte gultige Karten-Seriennummer an.","Fehler",JOptionPane.WARNING_MESSAGE,JOptionPane.OK_OPTION, null, options, options[0]);
                     //  int answer =((Integer) optionPane.getValue()).intValue();
                       if(answer == JOptionPane.OK_OPTION || answer == JOptionPane.CLOSED_OPTION){
                            jtf3.requestFocus(true);
          });but now the problem is, that it does not get closed at once.
    When i click OK then message appears again, and in second attempt it works.

  • JTextField does not visualize the text!

    Hello everybody,
    i have a problem with JtextFields.
    I have a Jtable with a ColumnHeader that contains a Button, a combobox and a JTextField.
    Normally i have 3 columns. When i try to move from a textfield to another textfield i can write in this one but the text is not visualized and i do not se the cursor in it.
    If i click a second time in the textfield, then the text gets visible.
    Here after the code of my UIText which extends JTextField.
    package com.wuerth.phoenix.ui;
    import com.wuerth.phoenix.ui.lov.*;
    import java.io.*;
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.text.*;
    import com.wuerth.phoenix.ui.*;
    import javax.swing.event.*;
    import java.awt.event.*;
    import java.util.Locale;
    import java.text.*;
    import com.wuerth.phoenix.util.PString;
    * This object is a generic ui field. Use them to get alphanumeric
    * text.
    * @author ing. Davide Montesin '99<BR><i>[email protected]</i>
    public class UIText extends JTextField implements TextEditor, PhoenixUIElement, FocusListener, KeyListener, ActionListener
    private DefaultPhoenixUIElement dui;
    // This object (is) was used by updateCorrect to find the correct background color
    // It is used for UIComboBox too.
    // protected final JTextField _jtextfield = new JTextField();
    // Background Color (mtm 010327 - UI Bug)
    private Dimension _preferredSize = null;
    private boolean _onlyUpperCase = false;
    String _oldText;
    * Construct a new UIText with the default length(15).
    public UIText()
    this(15);
    * Construct a new UIText with the specified length.
    public UIText(int length)
    super(length);
    setOnlyUpperCase(UIConfiguration.get().isUITextOnlyUpperCase());
    this._oldText = "";
    this.dui = new DefaultPhoenixUIElement(this);
    this.addFocusListener(this);
    this.addKeyListener(this);
    this.addActionListener(this);
    * Set to true if the object should return only uppercase String. This method
    * have priority over the UIConfiguration.
    * @param c if true the getAsText method will return a uppercase string.
    * @see com.wuerth.phoenix.UIConfiguration#setUITextOnlyUpperCase
    public void setOnlyUpperCase(boolean c)
    _onlyUpperCase = c;
    * Tell the object that this field is required. The field use warning color and error color
    * to tell to the user this requireness.
    public void setRequired(boolean r)
    this.dui.setRequired(r);
    this.updateCorrect();
    * @see setRequired
    public boolean getRequired()
    return this.dui.getRequired();
    * Set the mode for the element. Valid modes are: PhoenixUIElement.INSERT,
    * PhoenixUIElement.LOOKUP AND PhoenixUIElement.FIND. The mode influence the
    * validation process.
    public void setMode(int m)
    this.dui.setMode(m);
    this.updateCorrect();
    * @see setMode
    public int getMode()
    return this.dui.getMode();
    * Use this method to tell this object if it contain semantically correct value. The element
    * itself can't control if semantic is correct. It is responsability of the parent to check
    * semantic of the UIElements value. This method is a way to display that a ArticleNumber is
    * not correct.
    public void setSemanticCorrect(boolean c)
    this.dui.setSemanticCorrect(c);
    this.updateCorrect();
    * @see setSemanticCorrect
    public boolean getSemanticCorrect()
    return this.dui.getSemanticCorrect();
    * This method check if at the moment the uielement is corect at all: syntatically,
    * per range, semantically and requireness.
    * The window can use this method to check if the form can be saved or not.
    public boolean isCorrect()
    return this.dui.isCorrect();
    * This method tell the object to syncronize layout
    * information with the correctness informazion. For example, if
    * the uielement contain a wrong value then after calling this
    * method you are shoure that the background is red(error).
    * <BR>
    * The uiobject itself should call this object at most in this two case:
    * If the lostFocus event fires<BR>
    * If the content of the field is erased.
    // WARNING_COLOR and ERROR_COLOR have priority over
    // EDITABLE_COLOR and NOTEDITABLE_COLOR. (mtm 010327 - UI Bug)
    public void updateCorrect()
    // fire the propertyChange event if necessary before update
    // layout aspect.
    fireUpdate();
    if (isCorrect())
    // (mtm 010327 - UI Bug) Original version.
    // _jtextfield.setEditable(this.isEditable());
    // this.setBackground(_jtextfield.getBackground());
    // this.repaint();
    // Select between EDITABLE and NOTEDITABLE Colors
    setBackground(isEditable() ? EDITABLE_COLOR : NOTEDITABLE_COLOR);
    repaint();
    else
    if (getText().length() == 0)
    // Null object
    setBackground(WARNING_COLOR);
    else
    // Not null object
    setBackground(ERROR_COLOR);
    repaint();
    _setTooltipIfNeeded();
    } // updateCorrect() priority: WARNING_COLOR, ERROR_COLOR */
    * This method tell the object to syncronize layout
    * information with the correctness informazion. For example, if
    * the uielement contain a wrong value then after calling this
    * method you are shoure that the background is red(error).
    * <BR>
    * The uiobject itself should call this object at most in this two case:
    * If the lostFocus event fires<BR>
    * If the content of the field is erased.
    // In this version EDITABLE_COLOR and NOTEDITABLE_COLOR have priority over
    // WARNING_COLOR and ERROR_COLOR.
    public void updateCorrect()
    // fire the propertyChange event if necessary before update
    // layout aspect.
    fireUpdate();
    if (isEditable())
    if (isCorrect())
    setBackground(EDITABLE_COLOR);
    else
    setBackground(getText().length() == 0 ? WARNING_COLOR : ERROR_COLOR);
    else
    setBackground(NOTEDITABLE_COLOR);
    repaint();
    _setTooltipIfNeeded();
    } // updateCorrect() priority: EDITABLE_COLOR, NOTEDITABLE_COLOR/*
    * Overriden setEditable to set editable or not editable Background colors
    * (mtm 010327 - UI Bug)
    public void setEditable(boolean ed)
    super.setEditable(ed);
    // EDITABLE_COLOR and NOTEDITABLE_COLOR have priority over
    // WARNING_COLOR and ERROR_COLOR
    //setBackground(ed ? EDITABLE_COLOR : NOTEDITABLE_COLOR);
    //repaint();
    * Method from FocusListener interface.
    public void focusGained(FocusEvent e)
    System.out.println("show caret");
    setEditable(true);
    Caret caret = getCaret();
    System.out.println(caret);
    caret.setVisible(true);
    //moveCaretPosition(getText().length());
    enableInputMethods(true);
    * Method from FocusListener interface.
    public void focusLost(FocusEvent e)
    // Control if it is all ok
    // Format the field
    if (!e.isTemporary())
    // Make automatic completition when the user leave the field
    enter();
    public void processKeyEvent(KeyEvent e)
    char newKey = e.getKeyChar();
    if (_onlyUpperCase)
    newKey = Character.toUpperCase(e.getKeyChar());
    super.processKeyEvent(new KeyEvent(this, e.getID(), e.getWhen(), e.getModifiers(), e.getKeyCode(), newKey));
    e.consume();
    public void keyTyped(KeyEvent e)
    public void keyPressed(KeyEvent e)
    if (e.getKeyCode() == e.VK_F9)
    if (this.dui.getLOV() != null)
    this.dui.getLOV().addActionListener(this);
    this.dui.getLOV().start(this);
    public void keyReleased(KeyEvent e)
    public void actionPerformed(ActionEvent ae)
    if (ae.getSource() == this)
    enter();
    else
    this.dui.getLOV().removeActionListener(this);
    if (this.dui.getLOV().getValue() != null)
    javax.swing.FocusManager.getCurrentManager().focusNextComponent(this);
    dui.fireEditingCompleted(this);
    //--------------- controlla dimensione del testo... mi sembra pesantuccio!-----------------//
    // FontMetrics fm = this.getGraphics().getFontMetrics(this.getFont());
    FontMetrics fm = Toolkit.getDefaultToolkit().getFontMetrics(this.getFont());
    private void _setTooltipIfNeeded()
    String text = this.getText();
    int tWidth = fm.stringWidth(text);
    int cWidth = this.getSize().width;
    if(tWidth>cWidth && cWidth>0)
    this.setToolTipText(text);
    else
    this.setToolTipText(null);
    * JTextField setText method redefined to perform validation.
    public void setText(String text)
    if (_onlyUpperCase && text !=null)
    text = text.toUpperCase();
    super.setText(text);
    if ((this.getLOV() != null))
    if (this.getLOV().isWorking())
    return;
    updateCorrect();
    setCaretPosition(0);
    dui.fireEditingCompleted(this);
    * Sets the current text.
    public void setValue(String text)
    setAsText(text);
    * Returns the current text.
    public String getValue()
    return getAsText();
    public void setAsText(String text)
    this.setText(text);
    public String getAsText()
    String ret = this.getText();
    if (_onlyUpperCase)
    ret = ret.toUpperCase();
    return PString.trim(ret);
    public void setLOV(LOVWindow lw)
    this.dui.setLOV(lw);
    this.updateCorrect();
    public LOVWindow getLOV()
    return this.dui.getLOV();
    public Dimension getMinimumSize()
    if (_preferredSize == null)
    _preferredSize = super.getPreferredSize();
    return _preferredSize;
    public Dimension getPreferredSize()
    if (_preferredSize == null)
    _preferredSize = super.getPreferredSize();
    return _preferredSize;
    public void setColumns(int colno)
    // invalidate cached data
    super.setColumns(colno);
    _preferredSize = null;
    private void fireUpdate()
    boolean oldSemanticCorrect = this.dui.getSemanticCorrect();
    this.dui.setSemanticCorrect(true);
    boolean correct = this.isCorrect();
    this.dui.setSemanticCorrect(oldSemanticCorrect);
    if ((correct == false) && (this.getAsText().trim().length() != 0))
    return;
    String localOldText = this._oldText;
    this._oldText = this.getAsText();
    firePropertyChange(PhoenixUIElement.ASTEXT_PROPERTY_NAME,localOldText,this._oldText);
    * Inform the component that the editing is completed.
    public void enter()
    if ((this.getMode() == PhoenixUIElement.LOOKUP) && (this.getLOV() != null) && (this.getAsText().length() != 0))
    this.getLOV().isCorrectAuto(this);
    updateCorrect();
    dui.fireEditingCompleted(this);
    * This event is common to all uielement. The event editingCompleted is
    * fired each time the editing reach a complete form. Each swing ui element
    * has a different event to inform that the editing is completed: actionPerformed
    * on the JText, ItemSelected on the JList, focusLost to all elements.
    * <P>
    * <PRE><CODE>
    * actionPerformed focusLost itemsSelected ... enter()
    * \ | / /
    * \ | / _________/
    * \ | / ______/
    * editingCompleted <---------------- setAsText()
    * |
    * |
    * setRequired() ---> updateCorrect
    * setMode() ------/ |
    * |
    * |
    * propertyChange (ASTEXT)
    * </CODE></PRE>
    * Each specific event is mapped on the editingCompleted event. The editing
    * complete event fires an updateCorrect method's call. The updateCorrect
    * fires a propertyChange event if, and only if, the content of
    * the ui element is changed.
    public void addEditingListener(EditingListener ee)
    dui.addEditingListener(ee);
    * Removes the editingListener.
    public void removeEditingListener(EditingListener ee)
    dui.removeEditingListener(ee);
    * This method can be used as common way to set the value for
    * the ui element throught an object. If the object is of the
    * wrong type (like Date for a numeric) no set is made.
    public Object getAsObject()
    return this.getAsText();
    * Return the value in the field as object. For example UIDate return
    * a date object, UINumeric a Double object, UICheckBox a Boolean object, ecc.
    public void setAsObject(Object o)
    if (o instanceof String)
    this.setAsText((String)o);
    * Returns true if the editor is empty. False otherwise.
    public boolean isNull()
    return (this.getAsText().length() == 0);
    * Return the component associated with this editor. In the most cases
    * this is returned.
    public Component getComponent()
    return this;
    public String format(Object o, String pattern)
    return o.toString();
    public String format(Object o, String pattern, Locale l)
    return o.toString();
    public Object parse(String text) throws ParseException
    return text;
    public Object parse(String text, Locale l) throws ParseException
    return text;
    public String getPattern()
    return "";
    public int getAlignment()
    return JLabel.LEFT;
    public Object clone()
    UIText clone = new UIText();
    clone.setText(getText());
    return clone;
    try
    catch (CloneNotSupportedException cnse)
    throw new RuntimeException("Clone not supported?");
    private boolean _noFirePropertyChange = false;
    public void addNotify()
    _noFirePropertyChange = true;
    super.addNotify();
    _noFirePropertyChange = false;
    protected void firePropertyChange(String propertyName,Object oldValue,Object newValue)
    if (!_noFirePropertyChange)
    //System.out.println("NO!");
    if (propertyName.equals("ancestor"))
    return;
    super.firePropertyChange(propertyName, oldValue, newValue);
    public String getMultilangCode()
    return dui.getMultilangCode();
    public String getTooltipMultilangCode()
    return dui.getTooltipMultilangCode();

    Can you explain what are you trying to copy and where?
    Can't you copy text from website to the clipboard or do you have a problem with pasting that text?
    * http://kb.mozillazine.org/Clipboard_not_working

  • Listener to JTextField

    hi, I got a problem on JTextField Listener. I hope to verify if the text containing in the JTextField component is null and prompt to user. I use the following statement:
    String text = textfield.getText();
    if (text=="" )
    then // pop up a dialog window.
    but it seems failure to realize my desire.
    how can I do with it?
    many thanks

    Hello Janeuk,
    you have to use .equals(...) in order to compare Strings:
    if (text.equals(""))
    If you want to avoid blank strings, too, add a .trim().
    Bye Joerg

  • How to Remove Spacebar event from JFormattedTextField/JTextField

    Hello Friend,
    I have problem about JTextField.I want to remove or unregister Spacebar event from JTextField.
    I have used KeyMap,InputMap,also.
    So please help me

    Hello Friends,
    That is not ficiable for me.Actuall that JTextField is already use Document listener and focus listener and HexFormatter.
    In sort i am making a JFormattedTextField as Hex JTextField which will validate only 0-9 and a-f And A-F will be valide entry and remail it will ignore.
    I have made that one .but we require output like
    45 56 89 a4 59
    Here space will generate by programmer not user,he will enter only data....so i want remove space bar
    i have used this way but that is not working
    KeyMap space=txtBox.getKeymap()
    KeyStroke stroke=KeyStroke.getKeyStroke
    (KeyEvent.VK_SPACE,0);
    space.removeKeyStrokeBinding(stroke);
    but this not working

Maybe you are looking for

  • BI Java stack instalaltion

    Dear Gurus, We are going for Netweaver 7.0 EHP1  BW-BO implementation. We are going to install the seperate instances for the abap and java  for the BW landscape . We are going to install DEV abap and java on the same host. Abap stack is installed. w

  • Converting text, language options?

    Hello everyone, I'm trying to convert a pdf-document (about 200 pages) and make it into a word-document, so that I can make small edits to the text (the pdf is scanned from a book). Under "Content editing" i choose "export file to.." and then selects

  • Adobe Acrobat 7.0 Professional vs Snow Leopard

    Hello! When I try to print to Adobe PDF printer 7.0 I get this message: The printer software was installed incorrectly. Please reinstall the printer's software or contact the manufacturer for assistance. None of the old tricks from Leopard works... A

  • Java Files

    Hi, New to working with OA Framework and JDeveloper, am working with Oracle Applications and need to customize several java files and generate the class files. I found the class files in the $JAVA_TOP, where can I find the java files for the correspo

  • OCA_Abuse exception 6402

    Hi Experts, I am encountering this exception during migration process. Details: Migrating from BO XIR2(Linux) to BO4.1 SP4(Linux). I have changed FRS input and output path on BO4.1 to: Errors: Please advise. Thanks. Regards Yue Seng