Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: action listeners on java

  1. #1
    Member
    Join Date
    Oct 2013
    Location
    Cyprus
    Posts
    35
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default action listeners on java

    I want to set a jcombobox selected index to -1 when i click to enter text in a jtextfield.But when i set that line of code in jtextfield action performed then triggers the action performed of the jcombobox.How to set selected index of jcombobox to default without triggering the action performed method.
    Thanks in advance.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,853
    My Mood
    Mellow
    Thanks
    178
    Thanked 631 Times in 618 Posts

    Default Re: action listeners on java

    Show the JTextField's actionPerformed() method.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,190
    Thanks
    49
    Thanked 2,172 Times in 2,145 Posts

    Default Re: action listeners on java

    Can you make a Short, Self Contained, Correct Example that shows the problem?
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Member
    Join Date
    Oct 2013
    Location
    Cyprus
    Posts
    35
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: action listeners on java

    Quote Originally Posted by Norm View Post
    Can you make a Short, Self Contained, Correct Example that shows the problem?

      private void Customers_TableMouseClicked(java.awt.event.MouseEvent evt) {                                             
     
                carsModelcmb.setSelectedIndex(0);  //set selected index to 0(set to select) in the cars model combobox
                custDetailsList.setListData(new String[]{"Select"}); //set text to select in JList
                txtsearch.setText(null); //empty the search textfield

    on the execution of the line "carsModelcmb.setSelectedIndex(0)" then trigger the combo box action performed method which executes other code.

      private void carsModelcmbActionPerformed(java.awt.event.ActionEvent evt) {                                             
     
            if(carsModelcmb.getSelectedIndex()>0){ //solved with the current line of code
               code .....

    Any opinions are welcome.

    --- Update ---

    I have managed to develop an application in java for a hotel and the owner told me that he wants to do the following tasks: add guess or company profile, invoice, rooms availability, etc.Can you help me to find the right book to do the analysis and design of the particular system in order to create a good normalization and correct relation with the tables in order to build correctly the database tables.I hope you understand me.

  5. #5
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,853
    My Mood
    Mellow
    Thanks
    178
    Thanked 631 Times in 618 Posts

    Default Re: action listeners on java

    If the combo box action is doing something that isn't desired when the state of the combo box is modified, then change the code that is doing the thing you don't want.

    Remember, as the programmer you're in charge, it's your program, and you can make it do exactly as you wish. Don't let the code be in charge of you.

    As for helping you learn how to interface with a database, start searching the web. All of the info you need is there.

Similar Threads

  1. [SOLVED] Anonymous inner class with Action Listener and Abstract Action
    By shakes6791 in forum Java Theory & Questions
    Replies: 5
    Last Post: November 13th, 2013, 02:52 PM
  2. new here - into some java action
    By admaw11 in forum Member Introductions
    Replies: 1
    Last Post: July 5th, 2011, 08:58 AM
  3. Serializing Listeners
    By aussiemcgr in forum Java Theory & Questions
    Replies: 1
    Last Post: March 11th, 2011, 04:47 PM
  4. Action Listeners and Key Listeners Help
    By xctive in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 18th, 2010, 08:27 AM
  5. Action(s) Java is looking for beta testers
    By app.jbbres.com in forum The Cafe
    Replies: 5
    Last Post: June 29th, 2010, 06:45 AM

Tags for this Thread