如何在Java中使窗口看起来像这样?

如何在Java中创建一个如下所示的窗口:

帧

我想要窗口布局,而不是标准的Windows边框,我不知道如何调用它。

编辑:外观对我来说不起作用:

不适合我

这就是外观和感觉,你可以在这里找到详细的解释http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html

您需要首先设置外观并使用跨平台的外观(如有人在称之为金属之前评论过)。 然后在创建框架之前,您需要请求边框由外观绘制。

 try { UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName()); } catch (Exception e) { } 

这会将外观设置为您想要的外观。 由于跨平台的外观和感觉是Sun的JRE中的金属。

 // Get window decorations drawn by the look and feel. JFrame.setDefaultLookAndFeelDecorated(true); // Create the JFrame. JFrame frame = new JFrame("A window"); 

这将使创建的JFrame具有您描述的边框。

设置窗口的外观和感觉,以便在main方法中编写以下代码。

public static void main(String args []){
尝试{

  for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("windows".equalsIgnoreCase(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (Exception ex) { System.out.println(e); } java.awt.EventQueue.invokeLater(new Runnable() { public void run() { MainFrame mainFrame = new MainFrame(); mainFrame.setExtendedState(MAXIMIZED_BOTH); mainFrame.setVisible(true); InitDatabaseDialog initDatabaseDialog = new InitDatabaseDialog(mainFrame, true); initDatabaseDialog.setVisible(true); } }); } 

将其添加到main()方法:

 try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Windows".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(testjframe.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(testjframe.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(testjframe.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(testjframe.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); }