Java GUI compatible with Mac and Windows - java

I have a project whose GUI was implemented in MAC notebook, when I tried to run it in Windows, there is different GUI and also different buttons' characters. I checked the type of all used fonts, and I am sure they are all installed in windows, Are there any other things I have to consider to work in both platforms ?

In swing there exists a LookAndFeel which by default is set to be platform specific: adapt to the normal platform theme. A nice cross-platform look-and-feel is nimbus.
What the fonts are concerned: look at this where registerFont is called.

You can Swing as the same code you develop will run on Mac, Windows or Linux.
You can install Windows Builder for eclipse. Tute is here:
https://www.youtube.com/watch?v=oeswfZz4IW0
(till 5:05 in the video)
A comprehensive guide to Swing and its various components can be found here: https://www.youtube.com/watch?v=rgkWfz7Vy40

Related

Swing Application on Win 8 Platform

I have Swing Application which runs absolutely perfect on Windows XP but fails to give desired Look And Feel on Windows 8(Dimension of Frame and Dialog Changes).I googled a lot but no solution. Will I have to make some changes to my app before deploying on Win 8?
use layouts for your Jframe.
If you use IDE for design means the look and feel will change in another system.
so use layout for your design.
check this link click here
You can use this layout in Windows XP then try it Windows8.
This looks Will not change.

How can Java apps use tray icons in Ubuntu >= 13.04 (with AppInicator)

The system tray was deprecated in Ubuntu 11.04 in favour of the new AppIndicator. Since then, SWT applications couldn't show an icon unless the user used a whitelisting workaround included for backwards compatibility. Version 13.04 now removes that workaround, meaning SWT applications (which don't support appindicator) can no longer generate tray icons.
How do you guys go about making tray icon applications using Java? Preferably in a way that works both on Windows and Linux, and not necessarily with SWT any more. Thanks!
Well, who knew. This exists in awt, so it's natively supported: SystemTray, and it works with AppIndicator in Ubuntu 13.04.
That said, there's a bug that makes the icon transparent background amateur-gray :(

How to use Command-c/Command-v shortcut in Mac to copy/paste text?

I have a Java Swing application that i want to run on Mac OS X. I want to use the normal Mac copy/paste shortcuts to copy/paste text to a text field in my Java application.
Ctrl+c & Ctrl+v does the trick but i want to use Command+c & Command+v instead. How can i do that?
If you're using a 3rd-party L&F implementation it probably doesn't support the Mac's native keyboard shortcuts. The following code should reinstate the Mac's keyboard shortcuts for JTextFields after setting the L&F:
InputMap im = (InputMap) UIManager.get("TextField.focusInputMap");
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.META_DOWN_MASK), DefaultEditorKit.copyAction);
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_V, KeyEvent.META_DOWN_MASK), DefaultEditorKit.pasteAction);
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_X, KeyEvent.META_DOWN_MASK), DefaultEditorKit.cutAction);
Of course you'll only need to do this if you detect that the application is running on a Mac so that you don't affect the keyboard mappings for other OS's.
Have you seen, know of or are using the SWT (Standard Widget Toolkit) maintained by Eclipse? That has a key press (SWT.COMMAND) for command.
Are you running pure Swing? If so it should do that automatically(note it may not make the little menu animation if you dont use an Application bundle). If not then you will have to consult the documentation for whatever API you are using.
Just tested it and it works fine on Snow Leopard.

how to retain windows-like appearance of java GUI in fedora

I'm using netbeans 6.7.1 on windows. I created a jframe application . When i run the same application in my fedora core OS , the appearance becomes dull , the fonts and the spacing change.. How to avoid this - as the GUI is of prime importance to my application.
Please help..
You can't use the Windows look and feel on Fedora.
to quote Sun:
Note: The GTK+ L&F will only run on
UNIX or Linux systems with GTK+ 2.2 or
later installed, while the Windows L&F
runs only on Windows systems. Like the
Java (Metal) L&F, the Motif L&F will
run on any platform.
You are probably currently getting the GTK+ look and feel. You have 2 other options to try, Motif and Metal. You can see how to set a different look and feel here.

Beautifying a SWT application on Mac

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

Categories