jSeparator looks - Preview Design vs Run File (netbeans)

北城余情 提交于 2019-12-11 02:58:36

问题


I have this little problem. I'm using Netbeans. When I click on Preview Design I see the jSeparators like this:

But when I run the project this is what it looks like:

How can I fix this problem? I want the project to look like the Preview Design.

Thanks!


回答1:


When you run your window (JFrame, JDialog) / component (JPanel) in Preview Design it's displayed using system look and feel, but when you run your application UIManager uses a cross-platform L&F by default, also called Metal L&F.

I want the project to look like the Preview Design.

See related:

  • How to Set the Look and Feel
  • How to set jframe look and feel

Off-topic

This is one of the arguments against the use of GUI builders. You will lay-out all your components using Preview Design to arrange all your components. Let's say you use Windows and now you set the look and feel to system L&F so in your computer your application runs and displays prefectly:

public static void main(Strin[] args) {
    ...
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    ...
}

Awesome, it works! Now lets say a friend of yours likes your application and you share it with your friend. It turns out your mate uses Linux or Mac... Then the system look and feel won't be Windows anymore and GUI will probably look terrible. For instance consider this post: Different looks beetwen Preview and Runview You can see in the second picture that last row of components is cut in the half.

This happens because the Layout Manager used by NetBeans GUI builder is GroupLayout, which is designed to be used with GUI builders and it can be a really pain in the ass (sorry for the expression, but it's true) to make it work in a different platform than yours.

In my experience I've used builder for a couple of minor projects, intended to run all in the same platform, but when I really had to develop a cross-platform application it turns out a nightmare. So I strongly recommend you to forget about GUI builders and write your GUIs by hand.

See GroupLayout autogenerated code in NetBeans. There is a list of really good layout managers that can make your life easier and your applications UI truly cross-platform, as any Java application is supposed to be.



来源:https://stackoverflow.com/questions/25064031/jseparator-looks-preview-design-vs-run-file-netbeans

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!