问题
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