Results 1 to 6 of 6
Thread: runtime MenuBar Generator
- 10-24-2011, 12:01 PM #1
Member
- Join Date
- Oct 2011
- Posts
- 23
- Rep Power
- 0
- 10-24-2011, 09:55 PM #2
Re: runtime MenuBar Generator
To get better help sooner, post a SSCCE (Short, Self Contained, Compilable and Executable) example that demonstrates the problem.
Also, whenever seeking help with an exception, always post the stack trace and indicate which code line gave rise to the exception.
db
- 10-25-2011, 05:18 AM #3
Member
- Join Date
- Oct 2011
- Posts
- 23
- Rep Power
- 0
Re: runtime MenuBar Generator
<code>
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* NewJFrame.java
*
* Created on Oct 24, 2011, 12:37:17 PM
*/
/**
*
* @author vns08103
*/
import javax.swing.*;
public class NewJFrame extends javax.swing.JFrame {
/** Creates new form NewJFrame */
public NewJFrame() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jButton1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstan ts.EXIT_ON_CLOSE);
jButton1.setText("jButton1");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(132, 132, 132)
.addComponent(jButton1)
.addContainerGap(195, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILI NG, layout.createSequentialGroup()
.addContainerGap(199, Short.MAX_VALUE)
.addComponent(jButton1)
.addGap(78, 78, 78))
);
pack();
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
JMenu fileMenu = new JMenu("File");
JMenuItem fileMenuNew = new JMenuItem("New");
JMenuItem fileMenuEdit = new JMenuItem("Edit");
fileMenu.add(fileMenuNew);
fileMenu.add(fileMenuEdit);
JMenuItem helpMenu = new JMenu("Help");
JMenuItem helpMenuAbout = new JMenuItem("About Us");
helpMenu.add(helpMenuAbout);
menuBar.add(fileMenu);
menuBar.add(helpMenu);
this.setJMenuBar(menuBar);
this.setVisible(true);
//JFrame frame = new JFrame("New");
//frame.setJMenuBar(menuBar);
//frame.setVisible(true);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
JMenuBar menuBar;
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
// End of variables declaration
}
</code>
- 10-25-2011, 05:19 AM #4
Member
- Join Date
- Oct 2011
- Posts
- 23
- Rep Power
- 0
Re: runtime MenuBar Generator
The program is developed in NetBeans 7 as desktop application. I wrote a action command on button press and on press it will generate following exceptions
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \\
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* NewJFrame.java
*
* Created on Oct 24, 2011, 12:37:17 PM
*/
/**
*
* @author vns08103
*/
import javax.swing.*;
public class NewJFrame extends javax.swing.JFrame {
/** Creates new form NewJFrame */
public NewJFrame() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jButton1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstan ts.EXIT_ON_CLOSE);
jButton1.setText("jButton1");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(132, 132, 132)
.addComponent(jButton1)
.addContainerGap(195, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILI NG, layout.createSequentialGroup()
.addContainerGap(199, Short.MAX_VALUE)
.addComponent(jButton1)
.addGap(78, 78, 78))
);
pack();
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
JMenu fileMenu = new JMenu("File");
JMenuItem fileMenuNew = new JMenuItem("New");
JMenuItem fileMenuEdit = new JMenuItem("Edit");
fileMenu.add(fileMenuNew);
fileMenu.add(fileMenuEdit);
JMenuItem helpMenu = new JMenu("Help");
JMenuItem helpMenuAbout = new JMenuItem("About Us");
helpMenu.add(helpMenuAbout);
menuBar.add(fileMenu);
menuBar.add(helpMenu);
this.setJMenuBar(menuBar);
this.setVisible(true);
//JFrame frame = new JFrame("New");
//frame.setJMenuBar(menuBar);
//frame.setVisible(true);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
JMenuBar menuBar;
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
// End of variables declaration
}
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \\
run:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at NewJFrame.jButton1ActionPerformed(NewJFrame.java:7 9)
at NewJFrame.access$000(NewJFrame.java:17)
at NewJFrame$1.actionPerformed(NewJFrame.java:40)
at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultB uttonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.jav a:6267)
at javax.swing.JComponent.processMouseEvent(JComponen t.java:3267)
at java.awt.Component.processEvent(Component.java:603 2)
at java.awt.Container.processEvent(Container.java:204 1)
at java.awt.Component.dispatchEventImpl(Component.jav a:4630)
at java.awt.Container.dispatchEventImpl(Container.jav a:2099)
at java.awt.Component.dispatchEvent(Component.java:44 60)
at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4577)
at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:4168)
at java.awt.Container.dispatchEventImpl(Container.jav a:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2478 )
at java.awt.Component.dispatchEvent(Component.java:44 60)
at java.awt.EventQueue.dispatchEvent(EventQueue.java: 599)
at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:122)
BUILD SUCCESSFUL (total time: 5 seconds)
\\\\\\\\\\\\\\\\\ Image is attached for reference

Please help me.
Thanks in advanceLast edited by vishrut_n_shah; 10-25-2011 at 05:25 AM.
- 10-25-2011, 10:39 AM #5
Member
- Join Date
- Oct 2011
- Posts
- 65
- Rep Power
- 0
Re: runtime MenuBar Generator
JMenuItem helpMenu = new JMenu("Help"); ??
menuBar.add(helpMenu);
this.setJMenuBar(menuBar);
this.setVisible(true); //??? it is already visible //FRAME
Ofcourse this is not your problem. Your problem is more detailed.
AWT-EVENTS like action performed or mouseEvent are stored in a queue. when you trigger the button AWT-Event queue is empty .
Wow, most probably setVisible(true ) methods invoke paint method so a chain of event produced by this method. But there is not a event in the queue because Window(JFRAME) and its components are already drawn.Last edited by Grkn; 10-25-2011 at 10:43 AM.
- 10-31-2011, 07:46 AM #6
Member
- Join Date
- Oct 2011
- Posts
- 23
- Rep Power
- 0
Similar Threads
-
Vertical menubar
By Java Unknown in forum New To JavaReplies: 0Last Post: 02-22-2011, 05:50 AM -
Visual Editor MenuBar problems
By StevenJMUK in forum SWT / JFaceReplies: 0Last Post: 09-01-2009, 02:55 PM -
About MenuBar
By makpandian in forum AWT / SwingReplies: 1Last Post: 03-20-2009, 11:50 AM -
Help about Java Menubar
By makpandian in forum AWT / SwingReplies: 5Last Post: 02-09-2009, 08:17 AM -
menubar in splitpane
By masa in forum AWT / SwingReplies: 1Last Post: 12-16-2008, 09:01 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks