I've created a Java application and converted it into JAR format to redistribute.

It works fine on Windows 7, Windows XP, SunOS and Mac OS X 10.5 ... but whenever I try to run it on Ubuntu 10.04 I run into a few problems:

  • When running the application it will randomly quit without warning and without any error messages. This does not happen on any other OS.
  • I'm using setVisible() to hide some buttons attached to a toolbar in my text editor. In Ubuntu, when a button is hidden using setVisible(false) the space on the toolbar is left blank - whilst in other OS'es the remaining buttons flow sideways to fill the gap.

For the second one, I've tried manually using validate() after setting buttons as not visible, but that doesn't seem to have any effect. It was working without validate() on the other OS'es anyway.

Can anyone tell me more or forward me to some more information about these Ubuntu-specific issues? Preferably I'd like a workaround that I can use to ensure that the program works the same on every OS.

Searching on Google for terms such as "ubuntu java setVisible(true) bug" doesn't give me many relevant results. I've only found one other forum post and that was in relation to a JFrame not acting properly when setVisible(true) was used on it - and the problem was never resolved by the original poster.

Edit: If you require code I can give it to you. But as the program works fine on all but one operating system, I haven't posted it.

To rephrase my question:

Is there another way to achieve the same effect as setVisible(true) for JButtons on a toolbar, that works on Ubuntu?

Have you tried this on some other *nix distribution like Fedora, Gentoo etc? If they manifest the same problem, it can be confirmed that this isn't a Ubuntu specific problem and more so a problem with the Java implementation for *nix. If the same issue doesn't show up, then you are better off asking the same question in Ubuntu official forums since this might be something "Ubuntu specific".

Unfortunately I don't have access to any other Linux distro to test it.

I should probably write up a short test program, so that someone else on here can test it if they're running Fedora etc...

You should better check what installation of Java you using because Ubuntu 10.04 doesn't come with Sun Java and this has to be add it manually.
Simple check

java -version

You should better check what installation of Java you using because Ubuntu 10.04 doesn't come with Sun Java and this has to be add it manually.
Simple check

java -version

Would have replied earlier but was using Windows 7 at the time.

Here's the output from my Ubuntu installation:

~$ java -version
java version "1.6.0_18"
OpenJDK Runtime Environment (IcedTea6 1.8) (6b18-1.8-0ubuntu1)
OpenJDK Server VM (build 14.0-b16, mixed mode)

On Windows 7 I'm using 1.6.0_20 so although Ubuntu isn't using the latest version it's only 1-2 minor releases behind.

I'll see if there's an updated version of the OpenJDK available.

You can install Sun Java as explain in this thread

Hm it dows act strange. I done a quick basic test. When the setVisible(false) is executed it dissapears and the second button (that exec the function) comes in first's button place.

$ java -version
java version "1.6.0_18"
OpenJDK Runtime Environment (IcedTea6 1.8) (6b18-1.8-0ubuntu1)
OpenJDK Client VM (build 14.0-b16, mixed mode, sharing)

I can't make java -version to show me the 0_20 version.
I've installed the jre from sun's official site, then also from the command line. (i don't know if it overrided it).
Synaptic shows the 0.20 version, that it was installed. Java plugin control panel says that i have the 0.20 version.

$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/lib/jvm/java-6-sun-1.6.0.20/bin
alexandru@alex-desktop:~$ echo $JAVA_HOME
/usr/lib/jvm/java-6-sun-1.6.0.20
alexandru@alex-desktop:~$ java -version
java version "1.6.0_18"   // !what's this????
OpenJDK Runtime Environment (IcedTea6 1.8) (6b18-1.8-0ubuntu1)
OpenJDK Client VM (build 14.0-b16, mixed mode, sharing)
alexandru@alex-desktop:/usr/lib/jvm$ ls
default-java        java-6-openjdk  java-6-sun-1.6.0.20
java-1.6.0-openjdk  java-6-sun

The problem with the setVisible() still exists and NetBeans gives me the following error when running the project.

** (<unknown>:2160): CRITICAL **: menu_proxy_module_load: assertion `dbusproxy != NULL' failed

Thanks peter_budo for that link - am reading it now.

---

Hm it dows act strange. I done a quick basic test. When the setVisible(false) is executed it dissapears and the second button (that exec the function) comes in first's button place.

Could you please clarify what you mean by this?

You have two buttons:
[ A ] [ B ]

If you set A to be setVisible(false) ... does B move into A's place (like it does for me on Windows XP and Windows 7), or does B stay where it is and there's a gap where A used to be (what happens to be on Ubuntu) ?

Edit: And I'm using a JToolBar object, with buttons added to that. Not sure if that's significant (only just thought to mention it now). When you answer, could you also let me know if you're using a JToolBar, or a JPanel / JFrame / etc. ?

- leiger

Sorry, i do need to practice expressing myself clearer ;).
My test:
Created a simple form in netbeans and added to buttons:
[A]
I added code to B (jButton2)

if(jButton1.isVisible())
        jButton1.setVisible(false);
        else jButton1.setVisible(true);

The result when i press B (jButton2):

And pressing B again:
[A]
Adding a jtoolbar with the same buttons on it gives same results.

I guess it works then the way it should,no?
PS: i had a problem on 9.10:my java apps wouldn't close(exit) after i did some clicks on them.
I think something is wrong either with your sistem or with the JRE. Reinstalling one of them, or both, may solve your problem.
try

sudo apt-get purge <java_thingy>

So B moves to take the place of A, then moves back out when A re-materialises. I'm assuming that's what is meant to happen.

Doesn't work for me on Ubuntu 10.04, but it does work for you on 9.10 - I doubt that small difference would change anything? So it must be the JDK. I'll try installing the Sun JDK first and if that doesn't work, will re-install the OpenJDK.

Will post here with my results (I'm travelling and it'll be a few days before I am back home to try this).

No. I was talking about past times with 9.10 when i had some other java related problems. I am using 10.04 now.

Okay, I finally had a chance to install the SunJDK a couple of days ago, and once I told Ubuntu to use that one instead of the OpenJDK as it was doing by default, everything started working as expected.

I've since found out that the OpenJDK has a number of other bugs as well...

Thanks a lot for your help - I'm marking this thread as solved :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.