Metal look-and-feel for JavaFX - java

I have a rather large Java application that uses Swing extensively. The look-and-feel used by the application is Metal and we have a custom theme that lightens some of the colours. I'm building a new component within this application (it's a large project that will deploy in a few years) and would like to use JavaFX for all the GUI parts (several reasons, including being a little more future proof, better APIs, and new widgets I would like to use). However, I don't want to upset the common look-and-feel of the application.
Is there any way (aside from writing lots and lots of my own CSS) to make all the JavaFX components look like the Swing components?

To get a Swing Metal look in JavaFX, start writing lots and lots of your own JavaFX CSS. I know it's not the answer you want, but it is the answer that is.

You could put put the JavaFX components that you need inside the Swing Components. For example, you could put a JavaFX ImageView inside a Swing panel. That way, you get the Swing look (and compatibility) on the outside but the JavaFX functionality on the inside.
I found this tutorial helpful:
https://docs.oracle.com/javase/8/javafx/interoperability-tutorial/swing-fx-interoperability.htm
But other than that, I don't think JavaFX has a look and feel identical to metal.

Related

Java GUI - NOT Swing

I need a new way to create the graphical user interface of my application. I don't want to use Swing. I'm looking for something that looks a little different. Can you recommend me some other way of creating it, please?
Why not JavaFX ?
It is supposed to be replacing Swing as the standard Java GUI builder, so it would be a good option as it will be getting regular updates from Oracle itself. Additionally, being an officially sanctioned kit, it has plenty of tutorials, guides, and a decent (and growing) userbase that you can use for help.
And it uses CSS, which is good to learn as it can be useful in other applications. (Webdesign, etc.)
Finally, JavaFX is included with Java 8, so you don't even have to worry about installing a separate package! (Although adding a package is really not difficult if you prefer Java 7 or below.)
If your complaint with Swing is how it looks, note that you can change the look and feel of a Swing application very easily, or even write your own if you really wanted.
To get a look and feel that matches other applications on your system, you call:
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
At the beginning of your program.
The default L&F, called Metal, also has a couple themes you can choose from (or you can create your own):
MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
Yes, javafx could be the way for you.
You can create Views using FXML files instead of coding everything in java.
The learning curve is not too hard in my view (and I am far from being a guru).
The tool Javafx Scene Builder is here to help you create your views or controls in FXML and integrates nicely with netbeans, and I suppose also with eclipse.
You can adapt the look of your controls using css.
I would suggest to start here to see if it would fit your need:
http://docs.oracle.com/javafx/2/overview/jfxpub-overview.htm

Can JavaFX be included on a Java SE project?

I'm trying to create an Inventory project and have graphs on it. I'd like the graph to be created thru JavaFX and call it on a Java main class. Is it possible to add a JavaFX class to a Java project?
I'm using netbeans btw.
JavaFX for Java 7 is different from JavaFX on Java 8. My advice would be to go for Java 8. Then maybe NetBeans 8 too. JavaFX and swing/awt have different event threads, though under java 8 there seems to be a better integration.
JavaFX and java swing are two separate worlds. One might embed JavaFX in swing. Though if you are at the start of a basically new project, then you might go for pure JavaFX.
JavaFX uses "properties", wrapped values that can have change listeners on them / data binding. This separation from components makes dealing with the Model-View-Controller paradigm a bit nicer / different. JavaFX components themselves are a slightly more difficult, as swing provides a full API full of setters. It can be hard to make a column right-aligned for the first time. Another thing that makes JavaFX harder, is the use of callbacks with generic types, lambda expressions. Giving the correct signature not always is straight-forward.
So embedding JavaFX in swing might be a good approach if there is much swing experience or existing code: see
Embediing Swing in JavaFX (the other way around) and
How to Use JavaFX in Your Swing Application
If you mean, you have a NetBeans 7 Richt Client Application, then on the NetBeans.org there several small articles on JavaFX integration.

Java - Building GUI for application

I've written a lot of Java applications over the years, but the vast majority of them have been simple command line programs with only a few hundred lines and (at most) several classes.
My question is this:
How do I now design/code an interface to this application?? Where do I start? I mean are there any tutorials/resources which describe the steps involved?
I know Swing exists, but where do you start, and is it the only option?
Any help/assistance appreciated...
The rich client GUI toolkits for Java are basically:
AWT Sun's Abstract Window Toolkit was the original component kit for making GUIs, a toolkit based around using native components. AWT still contains the core of very important parts of J2SE GUIs such as Graphics/Color/Java 2D, Image & BufferedImage, printing, D'n'D..
Swing The current, main-stream desktop app. component toolkit. Swing generates the components internally, and allows setting a Pluggable Look and Feel to the GUI. Swing offers components & functionality not available in AWT such as JTable, JTree, support for formatted documents (e.g. RTF & simple HTML) in Swing components.. For more information see things that Swing provides beyond AWT.
Java FX 2 Intended as an (eventual) replacement to Swing, AFAIU.
SWT is another choice, not written by Oracle, uses natives. I would not recommend it for someone learning rich client programming, since it is a lot easier to get answers in relation to Swing.
You have to learn core GUI API java.awt and its sub-packages along with (extended API) javax.swing and its sub-packages. You may start - The Java Tutorial.
No, Swing is not the only option but it is where you should start. Swing is the "new and improved" version of some of the GUI objects in java.awt. Most of the Swing objects build off of their AWT counter parts our are completely new. Both Swing and AWT are a part of the core Java API so it would be best to start with the tutorial that AVD linked you to (The Java Tutorial)

What JComponents to use..?

Till now, I was using VB for developing applications. Now I have to use Java for developing the front-end. I am quite confused with the Components. Need help.. A book reference or site reference would also do the job.
Basically, I will be using MenuBar, ToolBar, a Frame with JEditorPane. Now if I want to use a small window which will be a child form, to write some notes, of the master frame, which Component should I use?
I guess you're looking for a JDialog or a JPanel. Follow the Swing tutorial. It has detailed guidelines for every component, and has a visual index of all the components.
You can use a JInternalFrame for this. Follow this link for a demo
Components are quite easy to understand. A detailed tutorial is given here. But to tell you the gist Components are nothing but containers. For example JPanel is a component which can hold another component for example a JButton. Since JButton is again a container, you can add one more component, a JPanel to it.
The order and placement of the components that you add are determined by layouts. You have different layouts viz Borederlayout, BoxLayout, Flowlayout, GridLayout, GridBaglayout each having its own pros and cons and behaviors on how it reacts when window is resized.
For an IDE, I would recommend using Netbeans as you can drag and drop components as well as take a look at the generated Java source code to get a better understanding.
You want to the develop desktop applications using java right?
You need:
-Installed JDK(Java development Kit)
-You will need an IDE. My favourite is Eclipse.
There are many out there, but maybe the most intuitive for beginners in java might be Netbeans.
-When creating applications that use the components you mentioned, you will be using the libraries in the pagcage javax.swing(See the documentation in the link)
-And finally, just one more suggestion(Optional), is to get also a most powerfull IDE, just for graphics, so you can speed up your programming.I suppose you would like to speed up your development. In that case i highly recommend you this tool: JFormDesigner
Watch the videos and in matter of a couple of hours you will be developing interfaces fast as light :)
I hope this is useful

Has anyone got an example of aerith style swing mixed with GUI maintainability of SWT editing?

My boss loves VB (we work in a Java shop) because he thinks it's easy to learn and maintain. We want to replace some of the VB with java equivalents using the Eclipse SWT editor, because we think it is almost as easy to maintain. To sell this, we'd like to use an aerith style L&F.
Can anyone provide an example of an SWT application still being able to edit the GUI in eclipse, but having the Aerith L&F?
Like Heath Borders said, SWT doesn't support L&Fs, so you have to use Swing for that. Aerith however does not base on a look and feel, but on custom painting on the components with a lot of gradients.
If you are looking for a Swing GUI Editor that is (nearly) as easy to use as VB, try the Matisse GUI Builder in NetBeans. There is also a version for Eclipse, but it is shipped with the commercial MyEclipse. If you want to learn more about writing apps with cool a cool GUI, have a look at the Filthy Rich Clients book by Chet Haase and Romain Guy.
If this does not convince your boss, try to resize the VB GUI and then resize the Swing GUI. ;-) And I would say a VB is really not very good to maintain in the long run...
SWT doesn't support look & feels. You can get different L&F's by altering your OS native L&F. The only exception is to using the eclipse forms toolkit. It still has the OS native feel, but strives for a web-browser-like look. It does this mostly by setting everything to SWT.FLAT, and using white backgrounds on everything. Occassionally, they have to manually draw outlines around controls that don't natively support it. If you're looking for custom L&F's that will appear across platforms, you really want Swing.

Categories