简体   繁体   English

表单布局问题-Java Swing GUI(Netbeans)

[英]Form Layout issue - Java Swing GUI (Netbeans)

I have this issue with the design of my application when running. 运行时,我的应用程序设计存在此问题。 The image below shows how I would like my application to look which is created in the design view of netbeans. 下图显示了我希望在Netbeans设计视图中创建的应用程序的外观。

表格编辑器

Here is how it looks when the application is running. 这是应用程序运行时的外观。

运行时的GUI。

The border is not even aligned with the text and the button component and scroll-wheel does not match the one in design view. 边框甚至与文本对齐,并且按钮组件和滚轮与设计视图中的边框不匹配。 Is there a way that in which i can apply this theme to my running application as the GUI design is hideous. 有没有一种方法可以将这个主题应用到正在运行的应用程序中,因为GUI设计很丑陋。

There's nothing wrong with the layout, it's simply that the form designer is showing the system look and feel and you're running with Nimbus. 布局没有任何问题,只是表单设计器显示了系统外观,并且您正在使用Nimbus。 Take a look at How to Set the Look and Feel for more details 看一下如何设置外观以获取更多详细信息

In you "main" class/method you will have some code that will likely look like... 在您的“主”类/方法中,您将拥有一些可能看起来像...的代码。

/* 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(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
    java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
    java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
    java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>

Which could simply replace with something like... 可以简单地替换为...

try {
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
    ex.printStackTrace();
}

which will cause Swing to use the system/native look and feel instead 这将导致Swing改用系统/本地外观

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM