JTextField input check (errorDialog if invalid) & JComboBox Focus

I have a JTextfield which does an input check when the JTextField focus listener's focusLost method is called.
If I loose focus by clicking in on a JComboBox. The check gets done ok and focus is returned appropriately to the JTextField without any problems.
But if I try to show an errorDialog when the input is incorrect, the focus is returned to the JTextField without any problems, but the JComboBox remains highlighted as though it is still selected!
I am using sdk 1.4... on a linux box. does anyone know why this happens? and can anyone provide a clean solution to this?
Thanx,
Diego Paloschi.

Hello Kleopatra,
Here's a little demo:
import javax.swing.*;
import javax.swing.event.*;
public class Debug extends JPanel
private JTextField t1;
private JComboBox c1;
private T1Verifier t1Verifier;
public void init()
     t1 = new JTextField("20", 10);
     t1.setInputVerifier(new T1Verifier(this));
     String[] s = {"v1","v2","v3"};
     c1 = new JComboBox(s);
     add(t1);
     add(c1);
public static void main(String s[])
     Debug d = new Debug();
     d.init();
     JFrame f = new JFrame("Debug");
     f.getContentPane().add(d);
     f.setSize(300,300);
     f.setVisible(true);
class T1Verifier extends InputVerifier
private Debug debug;
public T1Verifier(Debug debug)
     this.debug = debug;
public boolean verify(JComponent input)
     JTextField tf = (JTextField) input;
     float value = Float.parseFloat(tf.getText());
     boolean inRange = (value >= 0) && ( value <= 10);
     return inRange;
public boolean shouldYieldFocus(JComponent input)
     boolean valid = super.shouldYieldFocus(input);
     JTextField tf = (JTextField) input;
     if ( !valid ) {
     tf.requestFocus();
     JOptionPane d = new JOptionPane();
     d.showMessageDialog(debug, "Out Of Range.", "ERROR" , JOptionPane.ERROR_MESSAGE);
     return valid;
Even if u comment out the JOptionPane and just make the inputverifier return control to the textfield it still doesn't work! What am I missing? Or how would u doi it?

Similar Messages

  • Input check of report

    I have selection option parameter to choose the date range called so_dt. this field gets data from the table ztbl_name.
    Here is the common input check
    IF NOT ztbl_name[] IS INITIAL.
        SELECT dt
           INTO wa
           FROM ztbl_name
             UP TO 1 ROWS
          WHERE  dt IN so_dt.
        ENDSELECT.
        IF NOT SY-SUBRC IS INITIAL.
          MESSAGE E001(zmsg).
        ENDIF.
      ENDIF.   
    Can any body explain the code snippet above? and is it the best practice?

    Hi Anthony,
    Let me do couple remarks and explanations:
    1) IF NOT ztbl_name[] IS INITIAL is wrong. I assume zttbl_name table is a custom DDIC (created via ABAP Dictionary) table, therefore you can't ask DB if table is empty with this statemnent. Instead you may use SELECT (count), but here it is not necessary at all
    2) It is a bit more faster to use select single or select distinct instead of looping via table within select - endselect.
    3) isntead of creating wa structure you use structure defined by TABLES ztbl_name. This will create a strucutre of line type ztbl_name.
    4) If you require only certain fields (called projections) it is better and fater to move it only to specified destination i.e. INTO wa-dt, but anyhow this if ok too:)
    5) Always check if sy-subrc  = 0, not if not initial. In this case you can check also field sy-dbcnt which return no. of correctly read records
    Providing above will apply lets do some coding below:
    TABLES: ztbl_name.   "declare structure for the table first (this will be our work area)
    SELECT SINGLE dt FROM ztbl_name "this will implicitly put data to ztbl_name structure
    WHERE dt IN so_dt.
    IF sy-subrc = 0.  "alternatively use sy-dbcnt <> 0.
        "do your processing here
        "you address dt field as ztbl_name-dt
    ELSE.
          MESSAGE E001(zmsg).
    ENDIF.
    I hope it will give you some basic overview:)
    Cheers
    Marcin

  • Input Check in Table Control

    A table control is created in screen painter and an internal table was used to store particular data in ABAP program.
    Information were entered into the table through ABAP program(insert value into internal table). The input check generated by data dictionary do not work due to data not inserted from screen field. How can I solved the problem?
    Do I need to manually program the input check using module as following:
    FIELD f Module m.
    But how can I make the whole row ready for input and with cursor on particular column just like what was done with normal data dictionary input check?
    Message class 00 number 058 with text
    Entry & & & does not exist in &4 - check your entry
    can be used for compute the message.

    What are those conditions that will trigger the input check for my situation?
    I can only do that for those fields with check table.
    Here are what I had done:
    <b>Flow Logic</b>
          field EBAN-EKGRP MODULE CHECK_EKGRP.  " Purchasing Group
    <b>Module code</b>
    MODULE CHECK_EKGRP INPUT.
    TABLES:  T024.
      CHECK:  EBAN-EKGRP IS NOT INITIAL.
      SELECT SINGLE * FROM T024 WHERE EKGRP = EBAN-EKGRP.
      IF SY-SUBRC NE 0.
        MESSAGE E058(00) WITH EBAN-EKGRP '' '' 'T024'.
      ENDIF.
    ENDMODULE.                 " CHECK_EKGRP  INPUT
    However, this is not applicable for those without check table.
    Please help. Points will be awarded for helpful answers.

  • Check validation of JTextField input

    In my code, I have a JTextField which can only input 0 or 1, I want to check if the input is empty first then if it is 0 or 1. The following is my code:
    if (myJTextField.getText()==""){
    return "empty";
    else if (myJTextField.getText()!="0" && myJTextField.getText() != "1")
    return "not 0 or 1";
    but it does not work, where is the problem?
    Thanks,

    if (myJTextField.getText().length() > 0){
    try {
    int i =
    int i = Integer.parseInt(myJTextField.getText() );
    if((i != 0) || (i != 1)) msg = "wrong
    g = "wrong number";
    else processIt;
    catch etc...I think the logic operator should be && instead of ||?

  • JComboBox Focus

    Hi, I've got 2 problems ....
    1) I have a JComboBox. I tried various methods in the JComboBox API to try and change the gray color you get when keep pressing the combo box.
    But I cant get rid of it (I mean change it to appear in a different color)
    Does any one know how you can do that ?
    2) How can I get rid of the focus in a JComboBox when it get the focus.
    I mean in buttons there is method call
    button.setFocusPainted(false); that do the job
    But there are no such method in the combo box. Is there another way ?
    Thanking in Advance *2
    Shirantha.

    You can do the followings:
    JTextField txt = (JTextField) getEditor().getEditorComponent();
    txt.addFocusListener(new FocusListener() {
    focusGained() {
    // do highlighting here.
    });

  • JComboBox focus working differently in different environ

    in our application we are requesting focus in a date JComboBox from many places, not all developers are doing it consistantly. What is the best way? We are in test now. Our testers run the Application with Web Start. Some on Windows 2000. Some on Windows XP. The ones on XP ( and an older version of Web Start than I have, v1.2) are seeing the focus go to the little arrow thingy instead of the text area of the combobox when the following line of code is used:
    protected void focusOnDateBeanSection() {
    SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    getMyView().getDateBean().getJEffDateCBX().requestFocusInWindow();
    Any new thoughts on this, searching through older forums, found this:
    getJEffDateCBX().getEditor().getEditorComponent().requestFocusInWindow();
    why couldn't you just do this:
    getJEffDateCBX().getEditor().getTextField().requestFocusInWindow();
    and why not just .requestFocus() ?

    so I'm saying requestFocusInWindow isn't reliable accross platforms either. So should I :
    .getJEffDateCBX().getEditor().getEditorComponent().requestFocusInWindow();
    or
    getJEffDateCBX().getTextField().requestFocusInWindow();

  • JComboBox focus problem

    Hi all,
    I'm using a JComboBox, a JButton and a JTextArea added to a JPanel. What I doing is using the TextArea as a console, the JComboBox to enter commands in (and retrieve old ones) and the JButton to execute entered commands. This works fine except for one thing. After I have executed a command and output has been written to the textarea(console) I want the focus to shift back to the combobox so that the user simply can enter another command. Using requestFocus() the drop down menu part of the combobox receives the focus and not the textfield part.
    I have tried multiple ways of actually accessing the textfield component (combobox.getEditor().getEditorComponent().requestFocus()) to set the caret position to 0 but nothing seems to work.
    Any thoughts or ideas will be appreciated.
    Cheers,
    Marcus

    Try calling transferFocusBackword on your JButton instance. Hope this helps.

  • Input does not work when not focusing the desired track

    Hello
    Sitting and working on a track here pretty much for the first time in logic X. I work with much outboard gear so I always send channels out and back into an input.
    The input channel which comes from the outboard gear now gets muted if I do not focus the track in the mixer or the working area, and yes the input is marked on.
    Anyone know anything about this?
    Cheers

    You need to make sure that it also returns true during the apply request values phase of the next request and thus not only during the render response phase of the initial request.

  • Input "(ALL_MEMBERS)" has an invalid format

    Hello Fellow Coders,
    I am using BOBJ Design Studio version 1.3 and am facing a very weird error when executing my application.  I have three cascading drop down filters in my application for STATE, CITY and LOCATION.  Based on my state selection, only relevant Cities belonging to that state is populated in the drop down.  Same is the case with LOCATION drop down which gets populated based on CITY selection.
    The issue that I am facing is when I don't select anything for CITY, system sends ALL_MEMBERS as the filter criteria.  Eventhough my end result is correct, I get this error message Input "(ALL_MEMBERS)" for Ship To City Code has an invalid format.  In my code, I am sending blank for the filter values but it is still giving issue.  Has anyone ever came across this issue and would like to share it with me?  I do really appreciate y'all's input. 
    Please see the attached screenshot

    Hi Raj,
    Showing your original script will help us to get clarified with this issue ,
    to be generic When you select your STATE dropdown, the corresponding cities gets populated
    in the  CITY dropdown, when you select CITY, the corresponding LOCATION.
    The problem arises when you skip the CITY dropdown selection , but you have populated the location with the city selection .
    One thing which may help is call CITY dropdown Onselect event at the event of STATE dropdown selection so that it selects the default value.
    If you have already done all this, Kindly ignore and try to post the exact script which you have used.
    Thanks
    karthik Swaminathan

  • Restricting JTextField input

    Hello,
    New to swing programing, and I want to restrict the type of input accepted in a JTextField. For example, I want to only allow numeric characters. I tried changing the value on a caret event, but quickly realized that is not a good thing.
    Any suggestions?
    Thanks
    evster

    See JFormattedTextField

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

  • JTextfield input Date convert to java.sql.Date

    Hi. I have a textfield for users to input date in 'dd/mm/yyyy' format and I would like to format this input into java.sql.Date to be stored into a database. How should I go about doing that ?
    I did the following:
    SimpleDateFormat formatDate = new SimpleDateFormat("dd/mm/yyyy");
    java.util.Date invoiceDate = formatDate.parse(jTextField3.getText());
    java.sql.Date sqlDate = new java.sql.Date(invoiceDate.getTime());and when I input into jTextField3 the value '28/05/2008' , I found in my database '2008-01-28'. January and May is a few months off and is totally not what I wanted.

    Hi you did you code perfect, but you need to change the pattern for formatting the Date
    dd - date
    mm - minute
    yyyy - year
    here you are parsing month as minute, so the output may wrong..!
    If you need to format properly
    please use the below pattern
    {color:#0000ff}SimpleDateFormat formatDate = new SimpleDateFormat("dd/MM/yyyy");{color}

  • Allow to erase values under the input-check of the ALV Grid Control

    Hi,<br />
    in my ALV Grid I do have a cell which automatically checks the values entered by the user. When the user does not enter the values belonging to the DDIC Domain Value Range of the data element, the cell is rendered with a red border and an ALV error message comes up telling the user to enter the correct values from the F4 help.
    In general, this is really great, but in case the user needs to erase the value, this automatical ALV Grid error message keeps popping up asking him to enter at least one value from the value range.
    (I assume this is due to the fact that the Domain value range does not contain the value 'empty'.)
    <br />
    I would like to keep the functionality of checking the entered value but want to switch off the error message in case nothing was entered. How can I achive this?
    <br /> <br />
    This is what I did so far: <br />
    1. Upon initializing ALV Grid, I define the field catalog like this: <br />
    ls_fieldcat-fieldname = 'REACTION'.                       "#EC NOTEXT <br />
      ls_fieldcat-edit       = abap_true. <br />
      ls_fieldcat-coltext   = 'Reaction'.                       "#EC NOTEXT <br />
      ls_fieldcat-outputlen = '8'.                              "#EC NOTEXT  <br />
    <br />
    * This forces the user to set at least one value; not allowing him to delete it!! <br />
      ls_fieldcat-ref_table = 'CRMS_ES_FOREIGN_ATTRIBUTE'.      "#EC NOTEXT <br />
      ls_fieldcat-ref_field =  'REACTION'. <br />
      ls_fieldcat-key = abap_true. <br />
    <br />
      ls_fieldcat-checktable = '!'. <br />
      ls_fieldcat-f4availabl  = 'X'. "shows the handle for F4 help <br />
      ls_fieldcat-col_id = 7.
    <br />
    (I would assume here that the ls_fieldcat - structure would allow an additional field which allows empty values, but I could not find one!) <br />
    <br />
    2. For my ALV Grid instance, I am registering the F4 during initialization:<br />
    call method gr_fkt_grid->register_f4_for_fields <br />
            exporting <br />
              it_f4 = lt_f4. <br />
    <br />
          ls_f4-fieldname  = 'REACTION'.   "EC SYNTCHAR <br />
          ls_f4-register   = abap_true. <br />
          insert ls_f4 into table lt_f4. <br />
          call method gr_fkt_grid->register_f4_for_fields <br />
            exporting <br />
              it_f4 = lt_f4. <br />
    <br /> <br />
    3. Then I am setting the handler while initializing: <br />
          set handler lr_grid_event_receiver->handle_f4 <br />
          for all instances. <br />
    <br /> <br />
    4. I also have checking methods in PAI for the ALV cells, but they do not apply in this case, <br />
        since ALV itself performs this check described above. I cannot see a chance for <br />
        interfering myself in PAI. <br />
    <br />
    Does anyone have an idea how I could prevent the ALV Grid of bringing up the message "Enter a valid value" and <br />
    allowing to delete the cell content while keeping its checks in case the user enters a wrong value? <br />
    <br />
    Thank you very much,<br />
    regards,<br />
    Konrad<br />

    Hi Konrad,
    Inside the handler method for event DATA_CHANGED,  always suppress the error log by calling method activate_display_protocol with dialog = ''.
    Whenever u need error log call  method display_protocol based on ok_code(sy-ucomm).
    Ex:
    method data_changed.  " Handler method for event 'DATA_CHANGED'
    *Suppressing error log
        call method g_o_grid->activate_display_protocol        "  Always suppress error log when grid is changed
          exporting
            i_dialog = ''.
        if er_data_changed->mt_protocol[] is not initial.
          if ok_code = 'BACK' or ok_code = 'SAVE'.      "  Based  on  ok_code display error log
    *Display error log
            call method er_data_changed->display_protocol.
          endif.
        endif.
      endmethod.                    "data_changed
    Might solve ur problem
    Thanks,
    Edited by: Sap Fan on Oct 14, 2009 5:35 AM

  • Flash doesn't always prevent HTML from getting input events even if it has focus

    Hi,
    There's been two such problems for some time now.
    - Take any HTML page with enough content to be able to scroll down. Add an SWF in there, for example that page could be a Flash tutorial and the SWF illustrates one of its steps.
    If that SWF makes use of the mouse wheel, for instance to zoom in or whatever, it does receive the event provided it has focus but the HTML page ALSO does. So the page scrolls down and the SWF vanishes from view (while it zooms in its own content ).
    - There is a similar (worse) issue with Firefox "Search as you type" feature (Firefox > Options > Advanced > General > Search as you type checkbox). Sometimes, mostly with the letter A it seems, when you try to for instance move a character in Flash with WASD, Firefox will also trigger the Search as you type box, which steals focus from Flash. Pretty bad when you're gaming.
    Are you aware of these bugs ? Didn't find mention of them. Can they be fixed pretty please ?
    Thanks.

    Ok
    It's great that you guys are in close contact. Mozilla has been working a LOT on JS speed these past few years. In early days I think they took hints from you, but now the reverse could apply, you could maybe use Mozilla's work on JS to fasten AS3 ?
    Anyway! So I will show only the find as you type issue to Mozilla then, although they will have to wait a week because I can't spend more time dealing with Bugzilla right now, I made the case reproducible and that will be enough till next week
    So here is how you might be able to reproduce it:
    - Enable Firefox find as you type (FayT)
    - Open the HTML page in this zip and give focus to the game
    - Play around a few seconds (WASD, left click to shoot, right click to change weapon, target enemies with cursor position relative to character)
    - "Accidentally" click outside of the game area (which means inside the HTML page) while you're walking with WASD
    - FayT is triggered as expected. (Even though this can be an issue if the page is scrollable and FayT scrolls the game away from view)
    - Click inside the game ONCE
    - Either wait or play around some more, but do not click again
    - Once the search bar disappears, you lose focus. Pressing keys either has no effect or triggers FayT again.
    Expected: The game keeps focus when search bar disappears.
    Notes:
    - There are other, likely similar methods to reproduce this
    - Clicking a second time within the SWF prevents the focus issue to happen (I think. Maybe not with all methods ?)
    - It works with other HTML pages and other SWFs. You should be able to trigger the bug even with a barebones SWF that only registers key strokes, I think.
    - I didn't give you the step by step way to have focus locked in the SWF instead of away from it, but it should be similar. 2 clicks outside might fix it. Plus, I can't see a situation where this "reverse bug" would be annoying for the user.

  • PAI screen input check

    hi experts,
    i am new to abap, i have a screen 1000. if user enter 123 as value in text field, i want to make it to consider as 00123(number length 5). can u ppl guide me how to proceed with this.
    thanks in advance...
    regards,
    Viral

    Hi Viral,
    In the PAI of screen 1000, convert the value of field 123 as '00123'.
    You can use FM CONVERSION_EXIT_ALPHA_INPUT.
    For Example:
    Declare the a variable F1 of length 5.
    data: F1(5).
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        input         = value of field from screen "123
    IMPORTING
      OUTPUT        = F1.
    The value of F1 would be 00123.
    Thanks,
    Sowmya.

Maybe you are looking for

  • Trial version problem when using more than 1 track - does trial version same as full one?

    I am thinking of upgrading to Premiere Elements 9 as I have upgraded my laptop. But the trial version Premiere Elements 9 doesn't even perform as well (with the same media) as Elements 4.0 did on my old laptop. My new laptop is an HP Pavilion with In

  • Need help restoring AddressBook contacts (lost on sync with iphone)

    Hi, Just got a new iPhone 3GS, and have .mac. I had duplicate contacts in my iphone. To fix the problem, I deleted one of each, then synced my phone. I got the warning that 5% or more contacts would change, and continued (50% should change, based on

  • In general settings many apps are not accessible

    In general settings i cannot access to the social network settings. Neither face time, icloud and others. Thay are all greyed out. Why?

  • Error in JSF deployment

    SEVERE: Error starting static Resources java.lang.IllegalArgumentException: Document base C:\ecilpse3.0\eclipse\workspace\JSF_Web_app\WebContent does not exist or is not a readable directory

  • 3102 question - access from cell phone

    Hello, I am thinking about buying a SPA3102 after seeing the comments that you can access it from a cell phone or other landline. My wife's family is overseas, and I want to use the free international calling from my Voip provider when she is calling