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".
Related
I have a JTable in a JScrollPane but I'd like to change the look of the ScrollBar to something a bit better looking; a 'custom design'. Maybe put an image that a user can drag instead of the default thick blue bar. Is this even possible?
The main thing I'd like to do is change the thickness of the bar. My application uses a small window and the ScrollBar looks too thick.
Any help will be much appreciated.
Edit:
Thanks for the responses so far. I just found this; answers my answer, in part: java scrollbar thickness
Unfortunately I cannot provide a sample at the current moment, but you should definitely look into this
The BasicScrollBarUI class allows you to modify different features of a typical JScrollBar, such as various different colors, sizes, and shadow effects. This should be what you are looking for. Basically the idea is that you are supposed to override the installDefaults method and just modify the protected fields to your liking.
But, if you want to get fancy, I would highly suggest looking into JavaFX due to the amount of customizability it supports, one being CSS styling (which should be very helpful to you).
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.
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 need a multi-value JSlider (or a similar component) for an analysis application. The two features missing from the regular JSlider are the ability to have more than one knob and also the ability to add or remove knobs on the fly. The reason for this is that they will be used to partition the 0..100% range for a particular factor into two or more subranges which are fed into a binning algorithm.
After some unsuccessful googling, it seems I'll have to develop a custom component (which I'm not very good at, I've been coding in Java for 10 years, but have zero experience in Swing). Is it possible to extend (easily :-) the JSlider component? Or are there better alternatives, perhaps not Swing-based but web-based? I have some flexibility in selecting the GUI approach for this. The current analysis application is command-line so a Swing GUI would be most straighforward, but nothing really prevents me for turning it into a web app if need be.
Thank you!
Take a look at JXMultiThumbSlider in SwingX.
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".