Changing the default appearance of netbeans GUI controls - java

Hey I'm new to netbeans and I noticed a lot of applications (from textbooks) have a default style/appearance to their controls (buttons etc) as shown below.
(source: iforce.co.nz)
.
the appearance when I'm creating a GUI is just the standard windows xp or 7 button style. Is there a way to change this to the style shown in the image above?
Here is the appearance I am currently getting:
(source: iforce.co.nz)
.
Thanks in advance.

Yes, you can give Swing a Windows like look and feel with the following code:
try{
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
}
catch(Exception e){
System.out.println("UIManager Exception : "+e);
}

NetBeans will automatically choose a Look and Feel depending on your JDK and operating system. NB generated some code to set the L&F when you created the JFrame which made everything look like Windows components. If you want to change the L&F, look at the source for your JFrame and look for a collapsed bit of code that says something like "Look and feel setting code." If you expand it you can change it as you like, or even delete it, which will cause it to simply use the default L&F ("Metal"), which is the one in your picture. Bear in mind that you really shouldn't really just delete generated code, but I'm just trying to make a point here. If you're new to swing in general, I'd recommend writing some applications by hand, and they should just use the "Metal" L&F by default. This will allow you to get comfortable with working with swing. See here for more information.

See the nested layout example for code that offers a combo containing the available PLAFs, and allows the user to change the PLAF at run-time.

You can add Look and Feels. There are some free great looking ones which can be downloaded freely. If you only want Windows look and feel you can just add
try{
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
}
catch(Exception e){
e.printStacktrace();
}
Hope this answers your question.

Related

Is there a way to make generic-looking buttons in Java? [duplicate]

I am new to Java programming and want to whether it is possible to get the windows native look in Java GUI applications. Obviously Swing won't work.
Use the following:
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
Read UIManager and How to Set the Look and Feel for more information.
Try this....
The syntax is:
UIManager.setLookAndFeel(PLAF); (Pluggable Look and Feel)
So, you must include the below 3 lines.
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
SwingUtilities.updateComponentTreeUI(frame);
updateComponentTreeUI(frame);
SwingUtilities.updateComponentTreeUI(frame) is used for refreshing the frame after the change.
try this code:
javax.swing.UIManager.setLookAndFeel("Windows")

how do I create a Java swing UI like this?

Below UI is something I'd like to aim for. But I have no idea, how they have the "skin" of the app. On my end, the Java application looks like it was made in 1990s. I want to change a look to a more modern style.
What components are they using possibly here? JSplitpane for one. but I'm not sure how they created that "Dokument/Vorschau" tabs.
First using a look and feel like Nimbus, can easily change the look of your application to a have a more modern feel.
Second, you will need to customize the font, color, borders, node icons, etc. of each component type to achieve a non-standard look. Some of these can be changed with updates to the UIDefaults of the look and feel but many will be made by calling methods on the specific instance of the component you are dealing with.
Try a javax.swing.JTabbedPane.
If you really want to change the complete look-and-feel of your application from scratch, you should take a look at Synth L'n'F. You can define style and appearance of components and bind them to components which match certain criteria.
(My opinion on that matter: heavily themed apps usually look and feel out-of-the-place and only make it harder to use the app, so I'd actually try to avoid themeing)

look and feel in java

I work a lot with look and feel in java and it works well but the only problem that the only component that has no change is the title bar(caption) still have the same native look and feel of os(windows platform as example)
i want to know what's is the reason and how to fix this? any body help..........
thanks in advance
Check out Substance https://substance.dev.java.net/see.html
You can change the title bar look and feel with substance support.
Here are a few screenshots:
Some PL&Fs support rendering frame decorations, and some do not. I believe the Sun cross-platform PL&Fs (for instance Metal) support it, but platfrom-specific PL&F (for instance Windows) do not.
The feature is not on by default. To switch it on for all new frames use JFrame.setDefaultLookAndFeelDecorated. The API docs for the method show how to switch it on for frames individually.
If you want to create your own borderless window, instead of using a Frame/JFrame use a Window/JWindow. Frame/JFrame are extensions to Window/JWindow that provide borders and the maximize, minimize and close buttons. Usually those widgets are provided by the OS, but you can override them.
Use
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
Before any JFrame or JDialog creation.
Usually into main.

Getting java applications to look native on windows - how?

Is it possible to use Java to create apps that look native on Windows? I don't care if the solution is portable or not, because I only plan to target windows users. I am using Scala if that matters.
Sorry for the lack of details, but I have never used Java before so I'm not even sure if this is possible.
try {
// Set the Look and Feel of the application to the operating
// system's look and feel.
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (ClassNotFoundException e) {
}
catch (InstantiationException e) {
}
catch (IllegalAccessException e) {
}
catch (UnsupportedLookAndFeelException e) {
}
That should set the Look and Feel to the system look and feel. You would do this before any of your GUI code. For example, in your main method.
If you want to learn more about Look and Feels, I would check out the Java Tutorial on them, as suggested by carwash.
Everyone else has posted Swing things, so I'm going to play Devil's advocate and mention SWT.
SWT is a widget toolkit produced by the Eclipse foundation. It is a thin wrapper over the system's native GUI... for Windows, OSX, and various flavors of *nix (Linux, AIX, BSDs?, etc...).
This is the opposite route that Sun's JFC/Swing took, which draws its own components.
See here: Java™ Tutorials: How to Set the Look and Feel
try {
// Set System L&F
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (UnsupportedLookAndFeelException e) {
// handle exception
}
You have to use Windows look and feel.
You can specify it at the command line:
java -Dswing.defaultlaf=com.sun.java.swing.plaf.windows.WindowsLookAndFeel MyApp
Or in code
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
Here are the details: How to set the look and feel
It's strange no one has mentioned JGoodies yet.
The JGoodies Windows look&feel focuses on a precise emulation on Windows 95/98/NT/ME/2000 in the following areas: menus, icons, colors, borders, fonts, font sizes, insets, and widget dimensions. It honors the screen resolution (96dpi vs. 120 dpi) to adjust sizes, insets, and widget dimensions. (Source)
Yes, Java does have a Windows-native look and feel available on Windows. Look up how to change your look-and-feel and that should take you in the right direction.
You'd do something like:
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
(Which of course works only on Windows.) The result looks and feels reasonably native. More info e.g. here.
Your should use native Look&Feel

Can I use two different look and feels in the same Swing application?

I'm using the Flamingo ribbon and the Substance Office 2007 look and feel.
Of course now every control has this look and feel, even those on dialog boxes.
What I want is something like in Office 2007, where the ribbons have their Office 2007 look, but other controls keep their native Vista/XP look.
Is it possible to assign certain controls a different look and feel? Perhaps using some kind of chaining or a proxy look and feel?
I just discovered: Since Substance 5.0 the SKIN_PROPERTY is available.
It allows assigning different skins to different JRootPanes (i.e. JDialog, JFrame, JInternalFrame)
A little trick: I override JInternalFrame to remove the extra border and the title pane so that it looks just like a borderless panel. That way it is possible to create the impression, that different parts of a form/dialog have different looks.
Here is a library which will automaticaly change the look and feel. I am not sure it this will done for every component in a different way, but you should take a look at it. pbjar.org
This book should be useful if you want to go deep into look and feel /java-look-and-feel-design-guidelines-second-edition
I would be glad to see some code example, if someone can write it, feel free to get starting.
EDIT:
In this forum thread Thread i found the following description
Swing uses a Look & Feel (a PLAF).
PLAFs aren't attached on a per-JFrame
level. They are attached on a per-VM
level. It is almost impossible to mix
PLAFs within one application. I have
seen a few attempts, all failed.
Swing unfortunately does lots of "psuedo-global" things behind the scenes. AFAIK, the only way to do it consistently is to use the private AppContext API. Each AppContext has its own event dispatch thread and other "psuedo-globals".

Categories

Resources