Results 1 to 2 of 2
- 11-25-2011, 03:18 PM #1
Member
- Join Date
- Dec 2010
- Posts
- 7
- Rep Power
- 0
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.setActionCommand(ScriptGen);
Icon1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Icon1ActionPerformed(evt);
}
});
Icon2 = new javax.swing.JButton();
Icon2.setActionCommand(Standardisation);
Icon2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Icon2ActionPerformed(evt);
}
});
jToolBar1.add(Icon1);
jToolBar1.add(Icon2);
setToolBar(jToolBar1,jToolBar2);
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) {
oKBtnActionPerformed(mainEvent,splitPane,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());
}
else
{
sp.setRightComponent(new ClonePanel());
}
}
Can anybody help me understand why the actionCommand is not set while I click appropriate buttons
- 11-25-2011, 10:30 PM #2
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 asdbJava Code:CODE
* SSCCE : Java GlossaryWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
Fetching server time
By kkk in forum Advanced JavaReplies: 0Last Post: 08-20-2009, 03:26 PM -
Some problem in fetching record
By Shivraj in forum NetBeansReplies: 1Last Post: 03-27-2009, 11:19 AM -
Fetching sequence
By Shivraj in forum New To JavaReplies: 1Last Post: 03-19-2009, 02:30 PM -
problem with fetching data
By payal.mitra86 in forum JDBCReplies: 0Last Post: 05-24-2008, 01:29 PM -
Fetching rows from DB
By Java Tip in forum Java TipReplies: 0Last Post: 02-06-2008, 09:23 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks