I develop a number of desktop Java applications using Swing, and while Swing is quite powerful (once you get the hang of it), there are still a lot of cases where I wish some advanced component was available right out of the box.
For example, I'd really like to see easy-to-use components (without writing them myself, which I could do given enough time) like:
Multi-line label
Windows File Explorer-like Icons or Thumbnails view
Drop-down button (like Firefox's old Back button)
5-star rating widget
Combo box with automatic history (like the text field on Google)
An Outlook-style accordion-style bar
and so on
I know of a couple of sources of free Swing components, like SwingLabs, home of JXTable, JXDatePicker, and a few others.
Where do you go for Swing components beyond those included with Java itself?
The following are worth a look:
swingX
Glazed lists
Substance look'n'feel
Flamingo components
Ken Orr's Mac Widgets
Jide's open source components
As for: "Windows File Explorer-like Icons or Thumbnails view"
They are built in in swing.
File explorer icons are accessed through FileSystemView class ( it is used by JFileChooser ) when the L&F is Windows of course.
FileSystemView.getFileSystemView();
Icon driveIcon = fsv.getSystemIcon( new File("C:\\"));
And the Thumbnails icon can be retrieved with the sun.com class that are discouraged by Sun
sun.awt.shell.ShellFolder getIcon( boolean largeIcon )
But this one may not perform very well some times ( due to native resources handling I think ).
I know you can get an awesome wrapping labe and an accordion from javaswingcomponents, however they are not open source implementations.
Otherwise Jide and SwingX are great choices.
Related
I'm looking for a really simple widget: tree view on the left pane, folder contents on the right, switchable between icons, thumbnails, or detail view. Basically a functional (not pixel for pixel) emulation of Windows File Explorer, but within the Java app. How to do this using only built-in Java libraries? Or a very lightweight framework?
NOT A DUPLICATE
My question is different from the above and I now realize it's a little harder to explain than I initially expected. Two clarifications:
My question is not about a File Chooser. I'm asking about a File Explorer type of dialog. The difference is that a File Chooser is really focused on one task, choosing a file. A File Explorer is a little less focused, and lets the user browse around without a clear objective.
My question is not about native operating system UI / L&F emulation. At all. I'm asking about the basic capability to display the contents of the filesystem using icons and thumbnails. The style and borders etc are not part of my question.
EDIT
I'm looking for something like this
Notice how it's different from this (JFileChooser)
JFileChooser will do that if you are wanting something built in to Java.
https://docs.oracle.com/javase/7/docs/api/javax/swing/JFileChooser.html
If you are not using Swing but SWT (like Eclipse) you can use SWT FileDialog
You could use the AWT library to customly render the entirety of Explorer. Whilst the only hard part about this is correctly using layout managers to get components exactly where you want them and adding event listeners for each button, using AWT wouldn't make it look like Explorer on different operating systems because AWT uses the native system components.
You could check if the OS is not Windows and then use Swing if it isn't. In that case, you'd have to retexture every single used component such that its look and feel is the same as your targeted Windows version. Even if you did that, you'd still have to somehow change the JFrame's look and feel, which is possible using dark magic, but quite obscur. You can do this in a very quirky way, just setUndecorated(true) and manipulate the JFrame's boundaries until it lets you draw outside the JFrame, so that you can draw the Windows' decoration around it without resizing the Window. On top of that, you'd also have to check if it's maximised, as maximized windows don't quite look the same in Windows.
To cut things short, just use JFileChooser if you just want to allow the user to select one or multiple files. There isn't really any point in recreating Explorer, but if that's what you want to do, I'm not stopping you.
We have a very large Java Swing desktop application comprising of a great deal of views. Developers have done a pretty good job over the years in choosing appropriate class locations which reflect the general structure of our UI for these views. Most of this time this is very helpful in tracking down specific components that have bugs which need tending to. However, there are cases where finding a panel, dialog, etc is quite painful. It usually involves searching our properties files for unique string sequences that appear in the UI.
Does anyone know of a third-party tool that allows a developer to hook into a Swing application and click on a region of the UI to reveal that name/package/hierarchy of the component that was clicked?
SwingExplorer is the perfect tool for that. It does what you are describing, and even more (step-by-step drawing of Java2D, EDT violations, AWT events).
Does anyone know of a third-party tool that allows a developer to hook into a Swing application and click on a region of the UI to reveal that name/package/hierarchy of the component that was clicked
Darryl's Component Tree Model should provide you with this basic information. The demo shows how you would use the root pane as the container for viewing all the components. You would need to add a MouseListener to your application to get the Container that was clicked so you could display the component tree.
There's something doing exactly what you're looking for in the SwingX Demo. The JXTreeTable demo contains a tree of the components hierarchy, when the mouse rolls over a particular component, it is selected in the table.
You can have a look here
Couldn't believe it myself, but it could be really as easy as:
SwingUtilities.getRoot(...).list()
The list method exists since 1.0. lol.
I'm making a Java Application on Linux that uses sytray using Java 6 and Swing. The app looks great (uses the system look and feel) but the systray looks awful. I mean the systray menu looks like old widgedts (Motif?). I wonder if there is a way to set a look and feel or something to make the system tray prettier.
Heres a screenshot of the tray:
Have you tried JXTrayIcon?
I tested this demo from SwingHelper on Ubuntu 10.10 with Compiz and it looks cool.
UPDATE
As 2020, these links are broken and this solution has many drawbacks today. For instance, GNOME3 desktop environments had removed entirely system tray icons and they replaced it with AppIndicator.
Java's (AWT/Swing) System Tray support is broken today. I recommend using this Java library: https://github.com/dorkbox/SystemTray
From the site:
Professional, cross-platform SystemTray support for Swing/AWT, GtkStatusIcon, and AppIndicator on Java 6+. This library provides OS Native menus and Swing/AWT menus, depending on the OS and Desktop Environment and if AutoDetect (the default) is enabled.
For reference, you can found a copy of the original example at here
Swing uses emulated UI widgets. It has a number of styles or themes you can apply. If you would prefer more native results you will need to look for another widget toolkit. You have a few options:
If your needs are very basic, you may be happy with AWT that is the original Java UI toolkit. It uses native widgets, but has very limited library of widgets that it supports.
If you want to go beyond AWT, consider SWT, which is maintained at eclipse.org. It gives you a rich library of widgets, that are implemented natively.
Because Swing use AWT on Systray, if you want great looking on systray. Maybe you can try with SWT :)
I wrote my own library for it. Here is the link:
http://www.2shared.com/file/sQdjb6aG/jtray.html
Usage:
import javax.swing.jtray.*;
JTrayIcon.initSystemTray();
JTrayIcon icon = new JTrayIcon(img, "Tooltip", jpopupmenu);
icon.displayMessage(null, "Title", "Multiline\nsecondline", 3000); // 3 seconds
The library uses a few dirty tricks, so maybe it may not work on any Linux platform as good as in Ubuntu. It should work for Windows and OSX as well.
I haven't tried it myself, but if you're using Java 6 Update 10 or later, can you use the new Nimbus look and feel?:
Using Nimbus LAF
I've heard of tray icons using "JPopupMenu" on Ubuntu, which uses the Nimbus look and feel, so this may be your best bet:
Using JPopupMenu in TrayIcon
From what I've seen, using JPopupMenu alone would be a big improvement - coupled with Nimbus it should be awesome.
A quick & dirty workaround:
Create an undecorated JDialog, add a JPopupMenu for it and make it visible from your mouse listener of your TrayIcon as you want.
Looking for a means of displaying transient, non-modal dialogs in a Swing application. In other words, I'd like to pop up a semi-transparent box with some text in it that can be immediately dismissed, or will fade away in a set amount of time. Is there a library to do this? I don't want to reinvent the wheel if it already exists.
Growl screenshot:
Android Toast screenshot:
(source: devx.com)
This link provides information about "translucent shaped Windows" using Swing, though it does not provide the full sourcecode (but slides explaining what has to be done in order to achieve this). He basically uses JNA to avoid problems with repainting translucent windows and makes use of two libraries to easily add fade etc. support.
How do I create a J2ME app for cellphones with a GUI similar to the menus you see in Java games? I've tried MIDlets with Netbeans but they only show you one GUI element at a time. (textbox, choice, login, etc)
And which Java IDE would you typically design these GUIs in? Netbeans or Eclipse? and is IntelliJ IDEA usable for this aswell?
Do I have to write/get a library that draws GUI controls to screen via bitmap functions .. and keeps track of the keys pressed for focus?
Try to use LWUIT - nice UI toolkit for j2me:
https://lwuit.dev.java.net/
http://lwuit.blogspot.com/
You can also use minime: http://code.google.com/p/minime/
It's an open source GUI library for j2me. miniME works on canvas level (lowest level in j2me) to draw every control so your UI will look exactly the same whatever the handset it'll be running on. Other advantage are:
- miniME uses its own event loop to manage user controlled event (botton pressed, softbar, ..), so you Application will "behave" the same whatever the handset.
- miniME support the concept of Views and stack of view, in order to make navigation between different view/screens very easy.
Here is an example: A View is what you have on the screen at a given moment (for example the main menu screen), then to go to a sub menu, you create a new view, and by calling a simple API, you push it in the stack of Views. The previous view (the main menu) is still existing, but inactive. When the sub menu view complete his work (for example, user press back, or do a selection), you can just go back to the previous view by calling a pop api.
Your question is a bit vague to give a specific aswer, but you might want to check out LWUIT or Polish, you can develop both with either Eclipse or Netbeans.
As far as designing GUIs go, neither IDE will help from a visual perspective. J2ME UI development is all done in code, beyond creating any initial graphics in a proper graphics editor you don't get to see your output until you test.
Read up on the LCDUI package documentation which explains how the UI classes work and the differences between the 'High-level' and 'low-level' APIs.
I can't comment on which IDE to use - but I do know that to create custom UI (like the ones you see in J2ME games), you have to explicitly draw the GUI controls.
Beware that you may need to customize the GUI depending on the target phones. You have to cater for different screen sizes, key pad configurations, default theme etc. This would probably mean that you need different builds for things like different screen sizes which would drive up your Java Verified certification costs (if you need it).
You may be able to find a set of nice looking UI controls that you can buy online and use (try J2ME Polish). The easy way out of course, is to use default J2ME controls :)
Links to many j2me GUI libraries: link1, link2
I know that kuix is not bad and free - watch demo.
But i prefer to make my own gui elements - this is much more flexible (but takes some time).
As for IDE - you may want to make some kind of gui-editor tool, construct interface in it, save result to some file, and read it from your app.
It's way too cumbersome to write your own GUI, especially since there are so many available these days. If you're familiar with desktop development in VB.Net and C#, you might find "J2ME GUI" easy to use. You can download it from http://www.garcer.com/. It has a similar feel and makes it easy to learn. This is the kind of GUI that I expected to come standard with MIDP2 when I started mobile development. Would have solved a lot of issues.
If you are familiar with web stuffs then you can use KUIX (kalmeo.org/home/index) framework having xml and css supports. In place of It you can use also Polish framework (www.j2mepolish.org) it's also uses the xml in easy way rather than kalmeo kuix framework.