how do I create a Java swing UI like this? - java

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)

Related

How to set web look and feel only for a JCombobox

I want to set web look and feel only for a JCombobox in NetBeans.
Image :
Generally speaking in Swing you can't set the look and feel for any specific component but for the whole set of them. See How to Set the Look and Feel.
On the other hand, WebLaF provides extensions for Swing components that have a custom "Look" on their own with no need to set the Look and Feel to WebLaF for the entire application. In this case, instead of using a JComboBox you can use WebComboBox which is an extension of the previous one. However this custom look is limited and some features such as font (size, weight and family), renderers, pop ups, etc. don't change and still the same of the configured look and feel. So I wouldn't suggest you to do this at all and keep consistency either by setting WebLaf as Look and Feel or by using standard Swing components.
Consider the pictures below (note WebList is broken with Nimbus):
MetalLookAndFeel
NimbusLookAndFeel
WindowsLookAndFeel
WebLookAndFeel
Just add this after you set whatever default Swing UI you want and then you will get the WebComboBoxUI for all JComboBoxes only.
UIManager.put("ComboBoxUI", "com.alee.laf.combobox.WebComboBoxUI");

Localization and L&Fs

I thought it would be nice if I gave the user the ability to choose and switch between "themes" (L&Fs). I'd give him a choice between Java metal (default), System default, and maybe a couple more I'll download from the internet...
My application is also bilingual (you can pick between two languaes to be displayed).
However, it's important for my application to be fully translated. I can handle the simple stuff, naming JLabels, JButtons, titles of frames, etc...
But there are also some predefined components whoose string I cannot manage as easely (e.g. JFileChooser). I was told that I could change them using the UIManager, but that their strings are L&F specific.
Now, regardless to how much fun would be translating my application for each and every L&F, I hope there is some centralised way of controlling those strings.
After all, JFileChoose (e.g.) is the same component, no matter the L&F that is used, right?
It prints text on the same parts of itself, no?
So, there should be something I could access that would grant me "master" control over the text that is printed onto the predefined components, I assume...
Any ideas?
not easy job,
have to read Modifying the Look and Feel
most important is Changing the Look and Feel After Startup
have to accept that you have to override value for Keys into UIManeger too, NOTICE about one of Look and Feel
is possible that different L&F have got various Fonts and Colors for concrete JComponents, multiply by Native OS
in some cases is important if you'll to change Color or ColorUIResources (Font or FontUIResources)
JFileChooser is compound JComponents, you can to extract its members,
best place to start could be this idea,
Nimbus Look and Feel lives with own life

How to set all Java Swing GUI component backgrounds and foreground(fonts) colors at once?

I have tons of jbuttons, jtextfields, jlabels, jmenus, gui items and it is extremely time consuming to set the background color and foreground color one at a time.
I want to be able to color the fonts(foreground) and backgrounds all the jmenus, jmenuitems,jtextfields,jbuttons, etc quickly/concisely in my project instead of having to set them one at a time.
Is there any technique to do this more concisely instead of doing it one at a time?
1) most eficient way would be to use Custom Look and Feel, part of them have got a nice Themes
2) set value to the UIDefault, Listing UIDefault Properties
EDIT:
best of all UIManager Defaults by #camickr
You can combine Swing with CSS or use a Swing Look & Feel in order to create a standard look for your components. The Java site says:
Before we get into a CSS implementation, let's consider the alternative: a custom look and feel. Swing Look and Feels (L&Fs) are sets of classes that implement the actual drawing of components at a very low level (think lines and bitmaps). They can be swapped out for new ones at runtime, often to implement the look of a native platform; i.e., the JDK for OSX has a set of classes that make Swing apps look like native Aqua apps, with candy buttons and blue tint. Custom L&Fs are powerful, but not trivial or quick to build. You will usually have to touch 20 or so classes and implement a whole bunch of special drawing code.
So CSS is easier to use. The same article goes on to give a tutorial about how to implement the CSS with Swing. They provide a nice walkthrough of creating the right rules and then going on to implement them in CSS. However, this is not simply "copy and paste" code.
If you'd just like to use a package (without having to code it yourself) the answers to the question Can I use CSS for Java Swing? suggest Flying Saucer and Jaxx.
They're all JComponents so you can make an ArrayList of everything:
//Adding everything to the ArrayList
ArrayList<JComponent> myComponents = new ArrayList<JComponents>();
JButton b1 = new JButton("Button 1");
myComponents.add(b1);
JMenuItem item = new JMenuItem("Menu Item 1");
myComponents.add(item);
//Coloring the foreground/background
for(JComponent j : myComponents) {
j.setForeground(new Color("BLUE"));
j.setBackground(new Color("RED"));
}
If you use a Look and Feel that honors the UI constants in javax.swing.UIManager then you can just set them. There are values for e.g. panel background. If not or if you can't control the look enough by this you can write you own UI delegate that draws a specific component (e.g. javax.swing.plaf.ButtonUI for JButtons). If even this is not enough you can write your own Look And Feel. If you just extend the Metal LnF it is not that hard, you would write own UI delegates and set properties, like above, but centralized.

Java/Swing Volume Slider

Part of my application has a media component, and I'm looking for a nice volume slider I can use rather than a JSlider which looks a bit ugly for this purpose (or specifically, an extended JSlider with custom visuals would be nice). I could write one, but I don't really want to reinvent the wheel.
In terms of "nice" volume sliders - I'm looking on the lines of something like VLC:
Is there a (free) component like this already out there that I'm missing?
Jasper Potts has a nice blog post about how you can skin the slider using Nimbus Look and Feel: Skinning a slider with Nimbus.
Here is how it looks like:
By following the blog post, it's not very hard to make your own custom look on the slider. You may also be interested in my answer about customizing the JScrollPane using Nimbus Look and Feel with a full code example.
Since you will want a mute operation if clicking on the speaker, I suggest that you implement your own JSlider and plug it in to the look-and-feel; however, I would also highly suggest that you reused the BoundedRangeModel that the JSlider implements.
Or, you could subclass a JPanel and package two widgets in it internally; however, this technique will require a mediator pattern to keep the two widget's displays in sync with the one shared BoundedRangeModel.
Look at the old Sun documentation about making custom widgets, and use the source code for JSlider as a starting point. It's not as hard as it may seem; however, it does take some time to get it "just right".

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