0

I'm building a plugin for ImageJ using Swing GUI builder in Netbeans on OSX. The plugin is based on a working demo I found and altered to my needs.

Essentially when the plugin is run you see a dialog with 3 options. One to select a file (specifically a particular image file) another to open the image file using ImageJ. And a 3rd button to view the headers of the image file.

Buttons 1 & 2 work fine in both Netbeans and ImageJ and the 3rd button (Header button) works fine when I run the plugin in Netbeans.

The Header button when I run it in ImageJ throws an error:

err >Exception in thread "AWT-EventQueue-0" java.lang.UnsupportedClassVersionError: HeaderWindow : Unsupported major.minor version 51.0

I've done some research and it seems like the error is due to mismatched versions of Java but as for as I can tell both my plugin and ImageJ are using the same versions (otherwise the plugin wouldn't run at all). Here is the code on the page that throws the error.

I've tried forcing ImageJ to use an alternate version of Java ( with no luck).

Any help would be greatly appreciated.

Here is the code for the page that throws the error:

      /*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author benwoodruff
 */
public class HeaderWindow extends javax.swing.JDialog {

       static String[] annexA;
       static String[] annexB;
       static String[] annexC;
       static String[] annexD;
    /**
     * Creates new form HeaderWindow
     */
    public HeaderWindow(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jTextField1 = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jTextField1.setText("jTextField1");

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(146, 146, 146)
                .add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(174, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(98, 98, 98)
                .add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(176, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>                        


    public static void newScreen(String[] annexA, String[] annexB, String[] annexC, String[] annexD){
        HeaderWindow.annexA = annexA;
        HeaderWindow.annexB = annexB;
        HeaderWindow.annexC = annexC;
        HeaderWindow.annexD = annexD;

        newScreen();
    }
    /**
     * @param args the command line arguments
     */
    public static void newScreen() {
        /* 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 {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(HeaderWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(HeaderWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(HeaderWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(HeaderWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                HeaderWindow dialog = new HeaderWindow(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JTextField jTextField1;
    // End of variables declaration                   
}
fantaghirocco
  • 4,761
  • 6
  • 38
  • 48
bwoodruff1
  • 23
  • 1
  • 9
  • 2
    possible duplicate of [How to fix: Unsupported major.minor version 51.0 error?](http://stackoverflow.com/questions/10382929/how-to-fix-unsupported-major-minor-version-51-0-error) – A4L Sep 21 '15 at 15:02
  • What do you mean by "_I've tried forcing ImageJ to use an alternate version of Java ( with no luck)._" ? What Java version is shown when you click the ImageJ status bar? Did you read the [ImageJ FAQ](http://imagej.net/FAQ#Running)? – Jan Eglinger Sep 21 '15 at 15:20
  • My guess would be a third party library (perhaps org.jdesktop.layout) that is compiled for too new a version for ImageJ, Check and post the entire stacktrace of the exception so you can see which line of code and therefore which class and library is an issue. – WillShackleford Sep 21 '15 at 21:26
  • The text refers to three buttons, but there are no buttons on this dialog. Can you post the code with the buttons and their associated action listeners? – WillShackleford Sep 21 '15 at 21:28
  • Turns out the problem was this: org.jdesktop. I don't know if I clicked on the wrong thing when I made the new file but what it should have been using was: javax.swing.GroupLayout. – bwoodruff1 Sep 22 '15 at 13:22

0 Answers0