SWT is designed to be cross-platform, so it can run on a Mac. The problem is it commits the cardinal sin of Macland - it's UGLY. Toolbars don't look like Mac toolbars, status bars don't look like Mac status bars, etc.
Does anyone have any experience in making an SWT application look more like a Mac application? For example, by making platform-specific JNI calls via the 'OS' class in SWT? If so, how difficult was it?
(This question arises because we are looking at porting an existing SWT app designed to run on Windows)
Thanks
This is usually problem of Swing not SWT (SWT is directly linked to OS/framework provided widgets) - a quote from A gentle introduction to SWT and JFace 2:
SWT is a library that creates a Java
view of the native host operating
system GUI controls. It is host
implementation-dependent. This means
SWT-based applications have several
key characteristics:
1. They look, act, and perform like "native" applications.
2. The widgets provided reflect the widgets (the components and controls) provided on the host operating system.
3. Any special behavior
of the host GUI libraries is reflected
in SWT GUIs.
The pre 3.5 Milestone used to use Carbon framework and now the 3.5+ supports both 32/64bit Cocoa framework 1 so perhaps that has caused you confusion? Or can you be more specific, give us the version you use and some screenshots / sample code to reproduce?
I have been developing java application based on SWT/Eclipse RCP for a while on OSX and have not found and major problem with look&feel (of cause it does not 100% comply the Apple HID 3 as it complies with Eclipse UIG)
The best I can offer is to use either MacWidgets or Quaqua which are both free and in different stages of maturity. The bad news would be that they are both Swing based which is probably not what you want to hear.
You can make your application look and behave like mac application easily. Apple supplies a application called JarBundler with it you can put your menu items up where they belong it will also build a double click able executable, and you can set a icon.
Swing components on Mac OS X looks a lot like their cocoa components, and for OS X you can set some special flags that will make them just like their cocoa counter parts, such as you can set a flag for a JTextField and make it look like cocoa search field.
Also all Macs come with java pre-installed so thats one less worry.
I created support for the Mac OS native toolbar first for Carbon then for the Cocoa version of SWT. At the time I managed to transfer the eclipse perspective switcher to a native toolbar. I had no Obj-C experience so the Cocoa version was more work than the Carbon version, but when all is told, it is not really hard. After supporting the toolbar, I wrote some code to support Alpha Compositing, native image transparency, hardware accelerated effects (CAAnimation). For these, the more difficult part was to understand why some APIs were not even available to be generated by the Eclipse JNI generator. Turned out that the python bridge generator that provided by apple had not been upgraded for the Obj-C 2.0 Property syntax. When I fixed that, I was able to have the SWT JNI Generator spit out the missing APIs. From there, using them was the easy part. You can find some partial pieces of this in the eclipse.org bugzilla server.
I can't say it is always simple, but if you already know Obj-C, then you should be able to do anything you want. A couple days ago I started working on SWT Cocoa again, to add support for ARGB images (as opposed to the limited transparency support offered by ImageData).
Good luck.
I often use the odd "platform queries" to tweak an app. For example, its not really about dressing up an app and more about (for example) making the exit menu option say "Quit" on Mac and "Exit on windows. There are some Mac style guidelines that I can't get round like this but it may help.
See Patform.java for the switching class and ExitAction.java for an example of its use.
Good luck with it :D
Related
Is there a way for a Java Swing desktop application that runs in Gnome (3.14) on Linux (Debian) to make Gnome use the dark-themed (Adwaita) version of the window decoration?
I am using a custom dark Swing look-and-feel, and the only thing that is really annoying is that the title bar (native Gnome) is very bright. I already have used the Tweak tool to use Adwaita system-wide, but this doesn't kick in for applications that do not explicitly support dark-theme (e.g. Iceweasel, Icedove, Gimp, Libre Office, ...)
Here's a screenshot that illustrates the problem:
Ok, I found a viable solution for my specific system, so I will show what I did here. It is related to this question. In the accepted answer you can see that the issue is with legacy Gtk-2 applications, and that includes Java apparently. In the comments section there is a link to a Adwaita-Dark clone that applies the dark theme also to Gtk-2.
Unfortunately that theme is out-of-sync with Debian Jessie / Gnome 3.14 somehow, and if one installs that theme most widgets are broken in Iceweasel, Icedove etc. However. Since I don't care about the widgets but only the window title bar here, you can selectively use that clone only for the window decoraction.
So I downloaded that clone, and placed a symlink in ~/.local/share/themes/adwaita-again (you can use any name here it seems). Then in the Tweak tool, just flip the window style, like so:
And voilà, window title bars are dark for all applications:
This is also great when working with IntelliJ IDEA and "Darcula" theme. Linux FTW.
Edit: It seems the above approach does not fully work, at least after rebooting I am seeing the bright colours again. I found a more simple variant now: Copy the original Adwaita theme and patch the Metacity file. I have created a repository with my patched version.
Short history of problem:
After upgrading to Ubuntu 15.10 I had some problems with any Qt-apps after durable work with IntellijIDEA. In apps like tortoisehg I saw painting problems, like not filled areas or shifted text. It was fixed after reading post in archlinux forum. Just set up property for Qt and changed my openjdk to oracle's.
The next story, that possibly is relative to first, consists in my work in IntellijIDEA and other Java swing applications (like Netbeans RCP): after long term working some dialogs became transparent, were inaccessible or just clicked through it to something under. Reopen of the dialog or window helps, but my colleagues have same problems on other OS, like Fedora (with KDE).
This bug is annoying, because our product is written on Netbeans and works under *nix distributive. Sometimes we stuck with problem of click-through problem: dialog or window just clicked into window after it.
I think the problem in wrong settings of x-server and in Qt- and Java- toolkit clash. This leads to artifacts on both application groups.
Does anybody stuck with this problem and do you have some ideas to resolve it?
The possible reason is described in Russian here (https://toster.ru/q/267833?e=3090918#clarification_329784).
Some bugs of it are found in:
https://bugs.kde.org/show_bug.cgi?id=350976
https://bugs.launchpad.net/ubuntu/+source/openjdk-7/+bug/1512760
Summary: the Java and Qt applications use shmem that is never cleaned by Java, after some time Qt cannot use this memory to work right. Google it with words «Java Qt shmem».
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.
Hopefully no one has asked this question - didn't see it, but I apologize if it's a duplicate.
Anyway, I'm building some plug-ins with Eclipse RCP and am using SWT for my UI. I have a Composite that contains some panels and other items - anyway, I've noticed a bit of a difference in the appearance of the UI depending on how my OS is set up.
I'm running windows XP but am using the "classic" look/feel which is that of Windows 98. When it's like this - the UI looks fine; however, when I switch to the newer XP look/feel with that tacky blue bar and what not - labels and borders in my composite are different.
Is there a way I can force SWT to use the classic look/feel?
You need a javaw.exe.manifest bound to your application.
Here is an article that describes the problem:
http://www.javalobby.org/forums/thread.jspa?threadID=15414&tstart=0
I think it is a design decision of SWT to make it inherit the platform look and feel. I imagine this is partly to address the usual "java apps look rubbish/out of place/different" comments and partly to make it easier to load the relevant fragments at startup.
I don't know of any way to override the standard values.
Does them being different somehow interfere with the operation of the application? SWT is designed to inherit your user's preference for UI presentation. This is basic HCI - let your user decide what is tacky.
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.