【发布时间】:2014-01-03 06:14:42
【问题描述】:
http://postimg.org/image/fi1bwpfoz/ 如何在 java swing 中显示没有内部框架的菜单栏。我使用内部框架来显示菜单栏。什么应该是替代解决方案。
这是我的代码
私人无效 jLabel3FocusGained(java.awt.event.FocusEvent evt) {
// TODO 在此处添加您的处理代码:
}
/**
* @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
}
【问题讨论】:
-
但它应该在框架顶部移动。是否有任何替代方案可以像快照视图一样。
-
你在说什么?您的意思是要在不使用内部框架的情况下在顶部添加空间?
-
“什么应该是替代解决方案” - 您可以从阅读available tutorials 开始。别忘了,
JMenuBar只是另一个组件... -
如何将菜单栏定位到框架的中间。如果不使用内部框架,它将在框架顶部移动。请帮忙
-
如何使用 netbeans 设计器,netbeans 中有水平和垂直属性,没有位置。南北在那