I'm writing a game using Swing and want to achieve a distinctive "steampunk" inspired look for the GUI. This will require some animated components, chunky metallic borders etc.
I know that I can get nice effects by overriding paintComponent and doing all of my rendering for custom lightweight components in that method.
Is this the way to go, or should I be looking at developing a whole new pluggable Look and Feel?
What are the pros/cons of each?
Personally, I think you should go for a completely new look and feel... you may also be able to build it off of Synth L&F rather than writing everything on your own.
Nimbus is an example of an L&F written on top of Synth.
Creating a new L&F is a longer road, but keeps your code simple. (If you only need a few changes it's not worth the effort.) For example, the animations can be coded in the L&F part, so you don't need to worry about it in your components. I would suggest to edit a L&F that is close to what you need.
Related
How would I go about changing the Look and Feel of a JFrame and Swing components to custom pictures and what not? Is there a set of methods and API's or do I need to just make a custom JFrame that allows me to customize my JFrame further?
I'm trying to get something that looks like the World of Warcraft launcher or League of Legends launcher( best examples i've seen with custom everything xD). I'm pretty new to GUIs.
Not exactly an answer to the question, but since you're just staring with Java GUI, I'd recommend diving right into JavaFX -- a modern Java UI toolkit.
Please be sure to start with JavaFX 2.x -- not JavaFX 1.x, which is basically deprecated.
When I design my GUI using swing, the Swing Control Buttons are grey and the text easily fits on them. However, when I run the program the buttons become partly blue and the text no longer fits on them. Why does my program look different in the Swing Design than at run-time?
Why does my program look different in the Swing Design than at run-time?
Probably has something to do with your Look and Feel.
However, when I run the program the buttons become partly blue and the text no longer fits on them.
Probably because you are not using layout managers. Layout managers will make sure components are displayed properlly, even when switching between LAF's.
I can't guess what tool you are using to create your GUI but you are doing something wrong with the tool. If you need more help then post your SSCCE that demonstrates the problem.
I suppose you're using some GUI builder. Netbeans gui builder displays preview with native LaF, while program runs with default Metal LaF, which has different margins for components and font size. Either change LaF in your program to the one that works best for your layout, or make your components larger.
I can't seem to find anybody who has done or posted something like this; Essentially I want to design my own UI in photoshop and then slice down the images to use it in a Java application. Essentially coding in the PSD file as the GUI. Is this possible? If so, can anybody lead me in the right direction?
I'm not sure what editor to use for this sort of stuff. I am using the Eclipse IDE and I know there is a Visual Editor but, I already have the actual design for every component in a PSD file. All I want to do is to start incorporating this into the application. Thanks.
It depends on how far your design goes. If you simply want to have normal Swing components on top of your image this is easy. Convert your PSD into (for example) PNG, create a custom JPanel subclass that loads the image and overwrite the paintComponent() method to draw the image instead of the normal background. All child components can then be set to be transparent with setOpaque(false). This puts your image into the background and puts the components float on top of it.
If you want to change how individual components look, its a lot more work. You basically need to implement a new Look&Feel for Swing. I wouldn't recommend going that route, unless you really have to, we are talking about weeks of work here, and it requires a lot of testing to really make it work properly on all platforms.
Alternately, there are already tons of custom Look&Feels available, I suggest you take a look at some freely available ones (just google "java look and feel"). Many of them can be customized to some degree (how much depends on the actual implementation, so take a close look at the source/documentation for each of them).
You might want to take a look at NetBeans which has a Swing GUI Builder. You would have to redraw your components there, and then write all the code to process the events. It is sometimes good to start with that, though often times it is less frustrating to lay them out with code by hand as it can difficult to make changes in code and have the builder keep up. There is nothing I know that will let you start from a photoshop image and proceed to building a GUI. Sounds like a good project to make someone rich. :-)
Is there a way to write a Java Swing application with a custom chrome? Please take a look* at the frame for Microsoft's Zune 4.0 software.
I realize that colors, the shape of scroll bars, etc. are controlled by skins or looks and feels. Right now I'm trying to tackle the native window which houses the java components--the title bar mainly.
Thanks
(*) http://www.winsupersite.com/zune/zune4_shots.asp
By default the frame of a JFrame is native. This can be removed by calling Frame.setUndecorated. The Sun Window PL&F does not provide a title bar. You could hack aJInternalFrame so that it draws the frame, although that probably isn't going to be as easy as it may seem. Of course, if you are going the full custom route, you can draw whatever you want. From 6u10, Sun's JRE also provides APIs to make windows transparent and non-rectangular.
No part of a Swing component's look and feel is "native" in any way. Swing components are "lightweight", which means they are entirely drawn on the Java side, and not at all on the windowing system side.
To create custom "chrome" you create the UI delegates for one or more components. In yor case, you'd want to muck around with the delegates for JRootPane and JInternalFrame.
The Look and Feel of Swing apps are pluggable..that is it can change on the fly. You can create your own look and feel but its not a simple undertaking. To get started this tutorial explains. This article does a little more.
This project demonstrates what could be done. So its up to your imagination.
Does anybody know a way to "skin" Java desktop applications. (Like Winamp skins, or skins for MirandaIM)?
I don't want to create my own look and feel.
Yes, there are a few ways this can be done, but I don't know anyone that is really simple. Have a look at Nimbus: The New Face of Swing, it contains a few examples. You can often override the look of components or just change the colors.
Some links:
Nimbus Colors
Skinning a Slider with Nimbus
Nimbus UIManager UIDefaults
And you can always change to another LaF, in example Substance.
We've successfully used the NimROD Look and Feel to 'skin' the Swing look & feel. It works well, has several 'themes' already written for it, and can be added in a few lines of code.
Swing has built-in dynamic look and feel support. If you are talking about desktop apps, you might want to start with Lesson: Modifying the Look and Feel.
Edit: If you are talking about a webapp, then absolutely use different .css to acheive a skinnable interface. CSS Zen Garden is a great example/tutorial on how the same page can look entirely different with a different .css file.
For a project that's still actively maintained in 2022 and allows skinning of Swing applications try FlatLaf
FlatLaf is a modern open-source cross-platform Look and Feel for Java
Swing desktop applications.
It looks almost flat (no shadows or gradients), clean, simple and
elegant. FlatLaf comes with Light, Dark, IntelliJ and Darcula themes,
scales on HiDPI displays and runs on Java 8 or newer.
The look is heavily inspired by Darcula and IntelliJ themes from
IntelliJ IDEA 2019.2+ and uses almost the same colors and icons.
Another modern look and feel active maintained in 2022 is https://github.com/vincenzopalazzo/material-ui-swing
It include also a way to develop a custom theme in an external jar, like this one https://github.com/material-ui-swing/DarkStackOverflowTheme