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")
Related
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.
jframe to default show rectangle.
i want to know if it possible we show it similar to a circle?
and how?
It is possible to have non-rectangular JFrames. The simple way to do this is to use AWTUtilities.setWindowShape(Window, Shape). Read the page below for more details.
Someone else mentioned that it's possible to do this using the Robot class, but that unnecessary. Java now supports this natively where possible.
http://today.java.net/pub/a/today/2008/03/18/translucent-and-shaped-swing-windows.html
This article describes a clever hack that allows you to implement non-rectangular and translucent frames. You can apparently do it (non-portably of course) using native code hacks.
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)
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.
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".