Java questions/thoughts

Since I couldn’t do much this weekend, laid up with a leg infection, I decided to dive into Java a bit. I installed Eclipse and Windowbuilder and started working through some tutorials and playing around. BTW, the java tutorials posted here were very helpful. Thanks guys!

When I think of Java, I always thought of C++, and I hate C++ so I never really had much of a desire to learn it. But after playing with it, I kinda like it and it is kinda refreshing to see all these freely available tools and libraries full of fun components to play with.

I liked the integration between Eclipse and WIndowbuilder but I find Windowbuilder to be kinda clunky. It works but the window flickers every time I touch a control on it. Very annoying. It is also a real estate hog, which is an issue when running on a laptop.

I know it has been discussed before, but what is the preferred toolchain for Java for those who do use it? Also, should I be using Swing or JavaFX?

Phil

Hi, I can recommend two toolchains for GUI Desktop programming with Java:

  1. IntelliJIdea with JFormdesigner

The bundle IntelliJIdea and JFormdesigner are a perfect working Solution for Java programmers. The Guy Designer (JFormdesigner) works like a charm, nothing blinks, nothing flickers. But: it is somehow less comfortable than Netbeans on one site but more powerful on the other side.

  1. Netbeans

Netbeans with its integrated Swing Designer is really professional builded and has no problems in writing good and reliable Java Software with Swing GUI.

  1. Mobile

Mobile Programming for IOS and Android I am doing with codenameone while it comes up with GUI Designer and complete ready compiling servers for Android and IOS. Codenameone is not expensive (even with the free Version building and compiling of Android and IOS is no problem) and it comes with a good and reliable Support. Codenameone Basic is in the most cases more than enough (till 50 MB Jar Size), the Free plan comes with till ,5 MB Jar size. Enough for intensive testing and learning.

Web

Web is the question what you are doing most. I can recommend Vaadin (for the people which need a visual designer it is not for free) and also Apache Wicket. I am using both and I can say: it works, runs and is nice to program with.

If you want to do highly integrated Apps you can also use JMix (former Cuba Framework). It is really charming with Database Applications and Business Logic, therefore I am using it also sometimes.

That are my Toolchains, I hope it can help you to find your’s.

Sincerly
Thorsten

3 Likes

As the JDK from Oracle is not free

You may not: use the Programs for any data processing or any commercial, production, or internal business purposes other than developing, testing, prototyping, and demonstrating your Application;

I downloaded the JDK from JDK 16 Releases where it says

This page provides production-ready open-source builds of the Java Development Kit, version 16, an implementation of the Java SE 16 Platform under the GNU General Public License, version 2, with the Classpath Exception.

Unpacked it and put it into /Library/Java/JavaVirtualMachines

Then installed NetBeans and ran one of the example apps.

screenshot_523

Hmm, that does not look terribly Mac-like. Is there a way to have it look like an actual Mac app?

1 Like

You could probably use one of the OpenJDK implementations from Azul or other vendors
There are several

Seems to be geared towards Cloud and big corporations. Clicking on Pricing brings you to a website in Chinese. Don’t see anything there that says Mac like.

I am not worried at the moment if its mac like or not. I probably will never release a java program anyway. Just playing around right now.

It’s not all about you … :wink:

Do you recommend Swing or JavaFX? JavaFX is supposed to be more modern but also looks more difficult to implement.

? https://www.azul.com

downloads here
https://www.azul.com/downloads/?package=jdk#download-openjdk

Swing and JFX have different reasons you’d pick one over the other AS I understand it

JFX should map to native controls as I understand JFX implementations
But, as I understand it, it has beefier requirements and is less “the same from platform to platform” - obviously
And I do not know IF there are UI designers for it (there may be)

Swing on the other hands is less “native” but can be very similar from one platform to another
And you can use it with a WebSwing server which claims to take your desktop Java app & run it as a web app - no code changes (@thorstenstueker can speak to this better)
NetBeans has a built in designer for Swing
And there are others available

HA! Found it at https://alvinalexander.com/blog/post/jfc-swing/mac-osx-specific-property-settings-java-swing-applications/ :

try
{
  // set the brushed metal look and feel, if desired
  System.setProperty("apple.awt.brushMetalLook", "true");
  
  // use the mac system menu bar
  System.setProperty("apple.laf.useScreenMenuBar", "true");
  
  // set the "About" menu item name
  System.setProperty("com.apple.mrj.application.apple.menu.about.name", "WikiStar");
  
  // use smoother fonts
  System.setProperty("apple.awt.textantialiasing", "true");

  // ref: http://developer.apple.com/releasenotes/Java/Java142RNTiger/1_NewFeatures/chapter_2_section_3.html
  System.setProperty("apple.awt.graphics.EnableQ2DX","true");
  
  // use the system look and feel
  // UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception e)
{
  // put your debug code here ...
}

Now it looks like this:

screenshot_524

P.S. That is NetBeans with Swing

Edit: fixed link as the colon : was too close to the link

You can also use flatlaf the look and feelfrom formdev software or any other. Swing is really flexible. Your first showed example was the nimbus look and feel.

And yes: it is not native macos. But it is really flexible, rock solid and reliable.

How would you set up different looks for different targets? Eg this one for Mac and flatlaf for Windows?

personally I recommend nothing without thinking about the application needs. But for standard Desktop Applications Swing is a good base. While I need for mobile apps and for Web Apps different animals I need to do for this ones my development in FX or even others. There is no single line answer like you see.
In the most cases for Desktop Software Swing is perfect.

1 Like

:thinking::bulb: ah, you don’t know … :wink:

This MIGHT do the trick (at least it runs on Mac without an error; will need to install Java on Windows and see what happens there):

public static void main(String[] args) {
        
        if (isWindows()) {
            /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            javax.swing.UIManager.LookAndFeelInfo[] installedLookAndFeels=javax.swing.UIManager.getInstalledLookAndFeels();
            for (int idx=0; idx<installedLookAndFeels.length; idx++)
                if ("Nimbus".equals(installedLookAndFeels[idx].getName())) {
                    javax.swing.UIManager.setLookAndFeel(installedLookAndFeels[idx].getClassName());
                    break;
                }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Anagrams.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Anagrams.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Anagrams.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Anagrams.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        
        } else if (isMac()) {
            /* Set the Mac look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* For details see https://alvinalexander.com/blog/post/jfc-swing/mac-osx-specific-property-settings-java-swing-applications/ 
         */
        try
            {
            // set the brushed metal look and feel, if desired
            System.setProperty("apple.awt.brushMetalLook", "true");
  
            // use the mac system menu bar
            System.setProperty("apple.laf.useScreenMenuBar", "true");
  
            // set the "About" menu item name
            System.setProperty("com.apple.mrj.application.apple.menu.about.name", "WikiStar");
  
            // use smoother fonts
            System.setProperty("apple.awt.textantialiasing", "true");

            // ref: http://developer.apple.com/releasenotes/Java/Java142RNTiger/1_NewFeatures/chapter_2_section_3.html
            System.setProperty("apple.awt.graphics.EnableQ2DX","true");
  
            // use the system look and feel
            // UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            
            }
        catch (Exception e)
            {
            // put your debug code here ...
            }
        } else if (isUnix()) {
            System.out.println("This is Unix or Linux");
        } else if (isSolaris()) {
            System.out.println("This is Solaris");
        } else {
            System.out.println("Your OS is not support!!");
        }
        
        
        //</editor-fold>

        /* Create and display the form */
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                new Anagrams().setVisible(true);
            }
        });
    }

    

    private static String OS = System.getProperty("os.name").toLowerCase();


    public static boolean isWindows() {
        return (OS.indexOf("win") >= 0);
    }

    public static boolean isMac() {
        return (OS.indexOf("mac") >= 0);
    }

    public static boolean isUnix() {
        return (OS.indexOf("nix") >= 0
                || OS.indexOf("nux") >= 0
                || OS.indexOf("aix") > 0);
    }

    public static boolean isSolaris() {
        return (OS.indexOf("sunos") >= 0);
    }

So far I’m quite pleasantly surprised by Java …

I kn ow that trick long time but I have another philosophy. The medical applications are running on many platforms. As the users manual is written for one UI the OS may present another one. Therefore I use always another look and feel so it is the same on all platforms

So I have no other chance while the regulatory authorities are doing barbecue with me so that I have to write for every platform one manual. For that I was to lacy… :slight_smile:

Correction: I wanted to write LAZY and not LACY. Sorry for that and thank you to Markus Winter to show me the error with big portion of humor.

:flushed:

I was :joy: AND :sob: … how can I forget THAT image … :man_facepalming:

Oh I See. Theproblem is not that I do not want to work. The point is that in case of Software produced under regulation of EN/ISO 62304 and under EN/ISO 13485 I HAVE to do usability studies for every Software UI look and feel. That means if the Software looks different on Windows 11 for example I have to do a new usability study. The alternativer is that I am reducing the amount of platforms the platform is running on.

Since my customers did not follow me in buying Mac only but using Windows, Linux, MACOS and in some cases Unix Systems I had no other choice than choosing a look and feel which works for all of the platforms exactly the same. So I had to do one usability study with the UI and → only one documentation.

For getting the picture out of your brain take this here: :hammer: :hammer: :hammer:

I don’t think so … :roll_eyes:

Lazy:

lazy

Lacy:

lacy

:wink:

… but I take the hammer now, if it is all the same to you … :face_with_head_bandage: