Java Swing background one pixel off on MAC - java

I've created a Java Swing application using the Metal L&F. On Windows, everything looks just fine; but when running the application on a Mac, the background of all the GUI elements seems to be off by one pixel, bleeding out ouf their border to the bootom right.
A checkbox would look like this
I'd love to provide a code example, but i have no clue where the error could lie, as this behaviour occurs all over the application.
I'd appreciate any hint to the cause of this.

Related

Slick2D weird focus/graphical window glitch-like issue?

I'm making a basic game with Slick2D, and have pretty much followed thenewboston's tutorials to the line, up to the episode I have linked. However, when I run the code, the game window starts out of focus, in the background of my other windows. When I manually select it to look at it and bring it into focus, it looks like this:
Sometimes it's just a black window, and sometimes it's this glitchy-looking mess. Also, If you'll notice, the window itself has out-of-focus graphical qualities, even while in focus. None of the buttons at the top left do anything or even graphically respond to a click/hover. However, the window does close upon termination of the program.
I run LWJGL v2.9.3, Slick2D build 237, IntelliJ IDEA CE 2016.3.1 (tested with 2016.2.4 as well), and Mac OS 10.12 Sierra. I've tested this separately with Java 7 and 8, and both produce this result. If anyone can help, I thank you wholeheartedly in advance.
Edit: I've tried running a generic Slick2D demo from the internet (which can be found at gist.github.com/massimomusante/5459957), which should work since I assume it's a tested and very simple demo, but the same kind of thing happens with the out-of-focus black window. So I know it has to do with my setup rather than my game. In terms of native Slick2D/LWJGL stuff, I've tried running the original code with both the packaged Slick2D natives and the LWJGL natives, and the issue still persisted, so natives are likely not the issue either.

How do you make such complex GUI in Java? Is it possible with Gwt? Or need to use something else?

My goal is to make a simple GUI which almost look like this attached screenshot.
But while using Awt, Swing i have never found yet such combo/buttons nor i have found something like transparent window which showing my desktop background.
I am very desperate to make something similar, but i am not sure which framework i can use?
Can i do this above UI, with GWT? or is there something else?
Java has always supported translucent windows on Mac (from at least OS X 10.4 but probably way before that too).
However on Windows you need at least Java 1.6.0_10 to be able to do translucent windows directly from Java.
If for whatever reason you're stuck with an older Java you can use JNA. They've got examples as to how to create translucent windows on OS X, Windows and Linux and these examples work even on older JVMs.
As I type this JNA is located here:
https://github.com/twall/jna
Here's the code for their alpha/translucent example (where you can drag a picture with an alpha channel, like a PNG with an alpha channel and then choose the opacity):
https://github.com/twall/jna/tree/master/contrib/alphamaskdemo/com/sun/jna/contrib/demo
Now what you want to do can be done but there are gotchas: you need to be careful about several things. For example mouse events: if you want catch them or not when they happen on an area that is "fully transparent" (if you want to catch them, you can cheat and make your translucent window nearly --but not fully-- transparent).
What you want to do is a bit like a HUD: there are definitely HUDs done in Java but as far as I know they weren't build using GUI builder tools. You'll probably have to code it manually (or at least some part of it manually).
See this: How to Create Translucent and Shaped Windows

Substance L&F seems to break when deployed as webstart in java

I think I am having a weird problem:
I 've written a small application in java implementing a JTable to display some results.
I am also using the Substance L&F as my "skin".
Everything seems to be working perfectly.
When I upload the app on my server as webstart, strange things start to happen:
At some point my app generates a little JTable. Every time I mouse over that table,
the app's JButtons or menus or any swing control in general will stop responding. My only option is to close the window and restart the application. Note that the interface seems not to be frozen but like it's lost its focus... if I try to click in any of the table's cells, the UI will still be responsive (not on the swing controls though).
If I get rid of Substance, the problem goes off and everything is working normally again.
If I use another "skin" like JTattoo everything works flawlessly as well.
This only happens when I use the webstart. Does anybody know why..?
or better has any hints on how to fix it?

Why Java Swing behaves different on different systems?

Some swing code I write in my computer behave different on my colleague's computer, and in my PC, and in my notebook.
I wonder, is there something I can do to my Swing applications behave the same in every computer?
I want to have sure a algorithm I've tested in my computer will work the same way in my clients computers.
E.g.
Problem to focus JTextField works fine in my notebook with Windows XP, but not in my collague's computer with Windows XP, nither in my work computer with Ubuntu.
obs. the specific JTextField problem is not the subject of this question.
Problems with Swing apps on different platforms are common and they are caused by the simple fact that no matter what level of abstraction Java offers it has to play ball at some point with the native components of the underlying operating system. Event though Swing only uses the windows(frame) and draw everything by itself - discrepancies are very very common.
I develop a mutliplatform Swing application - and users on Windows are reporting all sorts of issues that Linux users don't have and vice versa. Sadly there is no silver bullet for such problems - extensive testing and nasty fixes are the only game in town.
And everything come exceptionally buggy and dirty in the area of pluggable look and feels. For example - resizing a JSplitPane with metal or nimbus is super fast(as expected), but if you use GTK+ plaf, everything goes to hell. This is a more serious(performance) problem - visual problems(missing borders, components not fitting properly containers, etc) have no end... Despite all of this Swing continues to be one of the best bet for multiplatform desktop applications.
I wonder, is there something I can do
to my Swing applications behave the
same in every computer?
I'm working on a complex Java Swing app that is shipped on OS X / Windows / Linux so just like Bozhidar answered, the issues are all far too real.
For some components, if you happen to have some UI design/programming skills, you can simply write your own component: I realize it's probably not a helpful answer, but it works.
For example, we wanted a drop-down "find-as-you-type" popup list (like the one that appears when you start a search on Google's main search page) that would look and work the same on Linux/Windows/OS X. After trying countless of "solutions" full of Swing idiosynchrasies that would not work everywhere (like, guess what, focus issues ; ) we decided to simply write our own component "from scractch".
We can intercept mouse and keyboard events on both OS X / Windows / Linux: we can write a component that not only looks but also behaves identically on all three platforms.
In addition to the "find-as-you-type", we also wrote our own tooltip-popup component, a dual progress bar (to progress bar in one to show producer/consumer style progress in a single bar) and a complex component involving several "text fields" which was absurdly complex and broken when we tried to do it using Swing (and broken in different ways on different platforms, like weird focus issues or caret not showing, etc.). So we "went dirty" and rewrote the entire component ourselves.
Result? Working identically on all platforms where Java can give you notifications about mouse and keyboard events...
I realize this may not be what you want to hear: I happen to have worked on both games UI and mobile apps UI back in the days and I have some graphic skills so it's not "hard" for me to write good looking UI components.
Sadly if you want some Java UI component to look and behave identically on all platforms, it's sometimes your only alternative...
I want to have sure a algorithm I've
tested in my computer will work the
same way in my clients computers
An "algorithm" should work fine.
You get problems when you rely on the ordering of events, which may be different on various platforms. One of the most common I know about is holding down a key so that is repeats:
a) on Windows you get keyPressed, keyPressed, keyPressed, .... keyReleased.
b) on Unix you get keyPressed, keyReleased, keyPressed, keyReleased ...
By the way a comment would be nice as to whether my suggestion in your "textfield" posting works or not. As I mentioned, I don't have a Ubuntu platform to test it on, so I'm curious as to the result.

Java Applet, AWT Refresh, issue on Mac OS X 10.4

We have a Java Applet built using AWT. This applet lets you select pictures from your hard drive and upload them to a server. The applet includes a scrollable list of pictures, which works fine in Windows, Linux and Mac OS X 10.5. We launch this applet via Java Web Start or within a web page.
Our applet does not behave properly in Mac OS X 10.4, regardless of the version of Java (1.4 or 1.5). You can find a screenshot of the incorrect behaviour, when scrolling, here:
http://www.lavablast.com/tmp/ui_error.png
Simply put, sometimes when scrolling the pictures end up overlapping the header or footer of the application. This behaviour does not occur on other platforms. On Mac OS X 10.4, it shows the pictures in the incorrect location when scrolling, which would not be so bad if it refreshed the screen after painting the image at that location. However, it does not appear that the application knows it painted it incorrectly and thus does not refresh.
If the window is minimized, resized or even moved, the application is refreshed and the incorrectly positioned elements vanish and the application resumes normally. I spent quite some time trying to force a refresh of the background image unsuccessfully. (the repaint the image directly, repaint all children of a few panels, etc. ) Thus, I am looking for any tips that would help me resolve this problem under Mac OS X 10.4 or, in the worst case, simply simulate a full applet refresh.
Until recently, everything was compatible with Java 1.1 but this has changed in a few locations which now require 1.4. I don't feel these changes created the issue, I am just providing this as extra information. If you are interested in implementation details of the scroll panel, I will investigate, but I am assuming this is a common platform bug for which workarounds must be known.
To replicate the problem, open the following Java Web Start application:
http://www.lavablast.com/tmp/opal-webstart.php.jnlp
Select a folder containing lots of images and play with the scrollbar. At some point (fairly quickly), you should get the refresh problem.
Edit: I followed the first suggestion here and replaced all my controls that feature background images with a Swing equivalent and the issue is still there. (Plus, there are numerous other fixes I would need to do to do a complete change). Any other ideas? A simple one line of code that forces a full refresh would be great :)
Edit2: The main thread creates the panels and launches X threads. Using an observer/notifier pattern, the threads complete and notify the main control, which adds a panel to the page. This is done via an EventQueue.invokeLater which, unless I am mistaken, should run on the right thread. The issue is at its most severe when scrolling even if no extra threads are running (as during the loading).
It does look like mixing lightweight (usually Swing) and heavyweight (AWT) components together. Moving to Swing you need to replace every last AWT component Swing equivalents (hint: avoid import java.awt.*).
Threading is often a potential problem for odd bugs. Swing components must always be used on the EDT (use java.awt.EventQueue.invokeLater). AWT is thread-safe is theory, but not in practice - also restrict usage to the EDT.
As you already require Java 1.4 you should consider some small changes to take into use SWING GUI instead, it solved our Applet refresh issues with AWT. (Mac, Linux etc)
If you have e.g. Panel, you need to replace it with JPanel etc.
You need this:
import javax.swing.*;

Categories

Resources