Question

enter image description herehttp://postimg.org/image/fi1bwpfoz/ How to show menu Bar without internal frame in java swing .i have use internal frame for displaying menu bar.whats should be an alternate slution for that.

enter image description here

here is my code private void jLabel3FocusGained(java.awt.event.FocusEvent evt) {
// TODO add your handling code here: }

/**
 * @param args the command line arguments
 */
public static void main(String args[]) 
{
    try {

        //String host = "jdbc:derby://localhost:1527/Employees";
        String host = "jdbc:mysql://localhost:3306/mysql";
        String uName = "root";
        String uPass = "paras123";

       //Class.forName("com.mysql.jdbc.Driver").newInstance();
        java.sql.Driver d=new com.mysql.jdbc.Driver();

        Connection con = DriverManager.getConnection(host, uName, uPass);

        Statement stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery("SELECT * from employee");

        while (rs.next()) {

            int col = rs.getInt("id");
            String first_name = rs.getString("firstname");
            String last_name = rs.getString("lastname");
            String job = rs.getString("job_title");
            //String p=col+""+first_name+""+last_name+""+job;
            System.out.println(col + " " + first_name + " " + last_name + " " + job);

        }

    } catch (SQLException err) {
        //err.printStackTrace();
        System.out.println( err.getMessage( ) );
    }





    /* Set the Nimbus look and feel */
    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
    /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
     * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
     */
    try {
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (ClassNotFoundException ex) {
        java.util.logging.Logger.getLogger(menu3.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(menu3.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(menu3.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(menu3.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
    //</editor-fold

    /* Create and display the form */
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            new menu3().setVisible(true);
        }
    });
}

// Variables declaration - do not modify                     
private javax.swing.JInternalFrame jInternalFrame1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu10;
private javax.swing.JMenu jMenu11;
private javax.swing.JMenu jMenu12;
private javax.swing.JMenu jMenu13;
private javax.swing.JMenu jMenu14;
private javax.swing.JMenu jMenu15;
private javax.swing.JMenu jMenu16;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenu jMenu3;
private javax.swing.JMenu jMenu4;
private javax.swing.JMenu jMenu5;
private javax.swing.JMenu jMenu6;
private javax.swing.JMenu jMenu7;
private javax.swing.JMenu jMenu8;
private javax.swing.JMenu jMenu9;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItem2;
private javax.swing.JMenuItem jMenuItem3;
private javax.swing.JMenuItem jMenuItem4;
private javax.swing.JMenuItem jMenuItem5;
private javax.swing.JMenuItem jMenuItem6;
private javax.swing.JMenuItem jMenuItem7;
private javax.swing.JMenuItem jMenuItem8;
private javax.swing.JPanel jPanel1;
private javax.swing.JPopupMenu.Separator jSeparator1;
// End of variables declaration                   

}

Was it helpful?

Solution

you can't go wrong using the BorderLayout to set the menu bar at the top regardless the resizing of the window and all. hope this helps.

JFrame frame = new JFrame();
frame.setLayout(new BorderLayout());
JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("Test");
JMenuItem item = new JMenuItem("test2");
menu.add(item);
menuBar.add(menu);
frame.add(menuBar, BorderLayout.NORTH);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top