NetBeans JFrame GUI all JLabels are grayed out when running - java

I'm having a problem with the GUI of a java project. I construct the GUI using the Netbeans GUI-builder. In the construction field, more specifically, Netbeans all the JLabels appear deep black but when I run the file (shift-F6) all the JLabels appear grayed out.
Here are some screens to clarify the problem:
In Netbeans: http://i51.tinypic.com/zl3z1j.jpg
While running: http://i56.tinypic.com/fnfwc0.jpg
What could be the cause of this problem?

This may be a look-and-feel problem. I seem to recall that the Netbeans GUI builder uses your system native look-and-feel. By default, however, your application will probably use the Swing LAF (the name of which I forget just now). This means that when you run the application, you won't see the same LAF as you see in the GUI builder. The colors used by the two LAFs are slightly different.
See this Java help page for some options on setting the look and feel. However, since it looks like you're going for a custom look anyway, you might be better off setting all of your colors explicitly.

Related

Custom Components in WindowBuilder

I am trying to make my own Java component for use with windowBuilder in eclipse. Creating the component is the easy part. The problem is getting eclipse to draw the component when one is created.
I have tried using SWT designer but that doesn't exactly work (can't make completely custom components).
Example:
If I want to create a Line component, which has 2 point members, I can't set the points from the design view of eclipse.
I was wondering whether this can be done.
I realize this might sound vague, and I will make any clarifications needed.
To preview use:
It should also be possible to add custom component to WindowBuilder:
right-click on the swing palette, then choose Palette manager .
You'll have the option to import a jar file to be added to the palette.
I am not familiar with an option to make a custom component visible in the static WindowBuilder view.

In Java, how to implement something like File Explorer?

I'm looking for a really simple widget: tree view on the left pane, folder contents on the right, switchable between icons, thumbnails, or detail view. Basically a functional (not pixel for pixel) emulation of Windows File Explorer, but within the Java app. How to do this using only built-in Java libraries? Or a very lightweight framework?
NOT A DUPLICATE
My question is different from the above and I now realize it's a little harder to explain than I initially expected. Two clarifications:
My question is not about a File Chooser. I'm asking about a File Explorer type of dialog. The difference is that a File Chooser is really focused on one task, choosing a file. A File Explorer is a little less focused, and lets the user browse around without a clear objective.
My question is not about native operating system UI / L&F emulation. At all. I'm asking about the basic capability to display the contents of the filesystem using icons and thumbnails. The style and borders etc are not part of my question.
EDIT
I'm looking for something like this
Notice how it's different from this (JFileChooser)
JFileChooser will do that if you are wanting something built in to Java.
https://docs.oracle.com/javase/7/docs/api/javax/swing/JFileChooser.html
If you are not using Swing but SWT (like Eclipse) you can use SWT FileDialog
You could use the AWT library to customly render the entirety of Explorer. Whilst the only hard part about this is correctly using layout managers to get components exactly where you want them and adding event listeners for each button, using AWT wouldn't make it look like Explorer on different operating systems because AWT uses the native system components.
You could check if the OS is not Windows and then use Swing if it isn't. In that case, you'd have to retexture every single used component such that its look and feel is the same as your targeted Windows version. Even if you did that, you'd still have to somehow change the JFrame's look and feel, which is possible using dark magic, but quite obscur. You can do this in a very quirky way, just setUndecorated(true) and manipulate the JFrame's boundaries until it lets you draw outside the JFrame, so that you can draw the Windows' decoration around it without resizing the Window. On top of that, you'd also have to check if it's maximised, as maximized windows don't quite look the same in Windows.
To cut things short, just use JFileChooser if you just want to allow the user to select one or multiple files. There isn't really any point in recreating Explorer, but if that's what you want to do, I'm not stopping you.

jSeparator looks - Preview Design vs Run File (netbeans)

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!
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.

how do i get a collapsable pane like the netbeans palette

i like the style of netbeans palette (Window -> Palette, best seen when creating a gui). i would like to integrate a similar collapsable panel in my application, but i have no idea how to find this component. i guess its not a standard swing component, although it looks kind of similar to a jTree. i poked arround the netbeans framework, but i couldnt find the corresponding class.
I know about swingx's JXTaskPane, but i would really prefer an easy, clean way to hide, show and group ui components, without fancy-animation bloating my app needlessly. The netbeans palette seems just perfect. but how is it called & where can i find it?

Java: Buttons and Labes Layout

What way would you suggest to layout (locate) Jbuttons and Jlabes in java in the fashion depicted in the picture below? Is there any tool for visually being able to place the components on a form in Java, rather than specifying the component locations in the code one by one.
Thanks
I am using eclipse
You can use Swing GUI Builder for visually layout component.
For Eclipse you can use WindowBuilder. Look for Installation guide with update site of eclipse. Also take a look at the Tutorial.
Yes, NetBeans comes with a visual UI builder for Swing.
Use NetBeans, its have a create GUI tool!

Categories