Results 1 to 2 of 2
  1. #1
    chandrupsekar is offline Member
    Join Date
    Dec 2010
    Rep Power

    Arrow Problem while fetching actionCommand

    Hi All,

    I have a main Frame which contains 2 buttons as icons added in toolbar. I have set an actionCommand implicitly as like:

    final static String ScriptGen = "ScriptGen";
    final static String Standardisation = "Standardisation";

    Icon1 = new javax.swing.JButton();
    Icon1.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {

    Icon2 = new javax.swing.JButton();
    Icon2.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {


    Now on clicking a button is it should open a popup (JDialog) where the user clicks either Ok or Cancel button. When Ok button is pressed it should open a different panel depends on the action command it is received.

    I have passed the action command as arguments while opening the popup dialog.

    The problem I am facing is whenever I click any button it is opening the correct panel for the first time, but while I clicked the 2nd button (icon) it is supposed to change in the action command and thereby 2nd panel. but it is not so. The action command remains with the previous one itself. I have to close and open it again, click the 2nd icon, to open the 2nd panel.

    The below code snippet is used while doing OK click action. The mainEvent contains the actionCommand

    oKButton.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent okevent) {

    private void oKBtnActionPerformed(java.awt.event.ActionEvent mainevt,JSplitPane sp,java.awt.event.ActionEvent evt)
    if(!("ScriptGen".equals(mainevt.getActionCommand() )))
    sp.setRightComponent(new TemplatePanel());
    sp.setRightComponent(new ClonePanel());

    Can anybody help me understand why the actionCommand is not set while I click appropriate buttons

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

    Default Re: Problem while fetching actionCommand

    Recommended reading: Code Conventions for the Java(TM) Programming Language: Contents

    Also, NetBeans visual designer's generated code with extra long method names and fully qualified class names is difficult to read. You need to learn to write your own code, at least for the purpose of posting an SSCCE* when asking for help. Oh, and you'll need to post an SSCCE; the code you posted in all probability doesn't contain the lines that's behind the problem.

    And use code tags to post codes -- [code]CODE[/code] will display as
    Java Code:

    * SSCCE : Java Glossary
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Fetching server time
    By kkk in forum Advanced Java
    Replies: 0
    Last Post: 08-20-2009, 03:26 PM
  2. Some problem in fetching record
    By Shivraj in forum NetBeans
    Replies: 1
    Last Post: 03-27-2009, 11:19 AM
  3. Fetching sequence
    By Shivraj in forum New To Java
    Replies: 1
    Last Post: 03-19-2009, 02:30 PM
  4. problem with fetching data
    By payal.mitra86 in forum JDBC
    Replies: 0
    Last Post: 05-24-2008, 01:29 PM
  5. Fetching rows from DB
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-06-2008, 09:23 AM

Posting Permissions

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