Swing JButton is not rendering properly on Solaris with Java 8
Asked Answered
Y

2

7

I've connected to Solaris 11 from my windows machine. I've set DISPLAY to my machine. And I'm using Java 8.

Note: This worked fine when using Java 6.

When I'm launching dialog then its button and other swing components are not getting rendered.

Observed that it works on o Windows 7 Enterprise o Windows Server 2012 Enterprise

I tried changing the L&F but that didn't work. When I used "GTKLookAndFeel" then buttons appeared but without text/label.

Any help is greatly appreciated. Kindly let me know if any elaboration needed. Thanks.

Code for my dialog is as follows

package com.ui;


import javax.swing.SwingUtilities;


public class SimpleDialog extends java.awt.Dialog {
    private static final long serialVersionUID = -8298472889742780386L;
    public SimpleDialog(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.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btnSkip = new javax.swing.JButton();
        btnRetry = new javax.swing.JButton();
        btnAbort = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        lblMessage = new javax.swing.JTextArea();
        btnViewLog = new javax.swing.JButton();

        setLocationRelativeTo(null);
        setMinimumSize(new java.awt.Dimension(600, 200));
        setModalityType(java.awt.Dialog.ModalityType.APPLICATION_MODAL);
        setName("Form"); // NOI18N
        setResizable(false);
        setTitle("Simple Dialog");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                closeDialog(evt);
            }
        });

        btnSkip.setText("Skip this Step"); // NOI18N
        btnSkip.setName("btnSkip"); // NOI18N
        btnSkip.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSkip_Click(evt);
            }
        });

        btnRetry.setText("Retry"); // NOI18N
        btnRetry.setName("btnRetry"); // NOI18N
        btnRetry.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRetry_Click(evt);
            }
        });

        btnAbort.setText("Abort"); // NOI18N
        btnAbort.setName("btnAbort"); // NOI18N
        btnAbort.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAbort_Click(evt);
            }
        });

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        lblMessage.setColumns(20);
        lblMessage.setEditable(false); // NOI18N
        lblMessage.setLineWrap(true);
        lblMessage.setRows(5);
        lblMessage.setName("lblMessage"); // NOI18N
        jScrollPane1.setViewportView(lblMessage);

        btnViewLog.setText("View log"); // NOI18N
        btnViewLog.setName("btnViewLog"); // NOI18N
        btnViewLog.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                // open some log file
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 580, Short.MAX_VALUE)
                                .addGroup(layout.createSequentialGroup()
                                        .addComponent(btnSkip)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(btnRetry)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 87, Short.MAX_VALUE)
                                        .addComponent(btnViewLog)
                                        .addGap(79, 79, 79)
                                        .addComponent(btnAbort)))
                                        .addContainerGap())
                );
        layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 149, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(btnSkip)
                                .addComponent(btnAbort)
                                .addComponent(btnRetry)
                                .addComponent(btnViewLog))
                                .addContainerGap())
                );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /** Closes the dialog */
    private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
        setVisible(false);
        dispose();
    }//GEN-LAST:event_closeDialog

    private void btnAbort_Click(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAbort_Click
        this.setVisible(false);
    }//GEN-LAST:event_btnAbort_Click

    private void btnRetry_Click(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRetry_Click
        this.setVisible(false);
    }//GEN-LAST:event_btnRetry_Click

    private void btnSkip_Click(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSkip_Click
        this.setVisible(false);
    }//GEN-LAST:event_btnSkip_Click

    public static void main(String args[]) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {

                SimpleDialog dialog = new SimpleDialog(new java.awt.Frame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAbort;
    private javax.swing.JButton btnRetry;
    private javax.swing.JButton btnSkip;
    private javax.swing.JButton btnViewLog;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea lblMessage;
    // End of variables declaration//GEN-END:variables

}
Yon answered 4/8, 2015 at 10:46 Comment(7)
Is the Solaris instance headless?Electrostriction
thank @Electrostriction for your response. I'm not sure whether that Solaris is headless nor not. However, please note that it works fine when I connect via Windows Server 2012 and Windows 7 machine.Yon
It is unclear what machine you are talking about when you state "I've set DISPLAY to my machine." Given the fact you wrote you have no idea if the Solaris machine is headless or not, I assume your are not rendering the swing button on Solaris but (indirectly) to something else. Are you running an X11 server on your Windows machine?Kovacev
Also please state what precise Solaris update/sru you are using (pkg info kernel | grep FMRI) and what precise jvm this is (java -version).Kovacev
Is there any reason why you use java.awt.Dialog instead of javax.swing.JDialog for your Swing dialog?Heliostat
@Heliostat Thanks for the observation and good catch. This got slipped from my eyes. It was a legacy component and is using AWT classes at various places. Moving to Swing Dialog worked on Solaris machine. However, this was a pretty late as we have already released our product with recommendation to use Windows Server 2012. Although the using Swing dialog worked, the question stands still why the AWT dialog didn't work in first place? Nevertheless, you certainly deserves bounty !! Thanks a lot..Yon
@Heliostat Above was just a sample code I wrote, in actual code, the package has been imported so fully qualified name wasn't used. But putting fully qualified name here got us to catch it.Yon
M
1

To apply look and feel you need to provide two commands:

UIManager.setLookAndFeel(lnf_name);
SwingUtilities.updateComponentTreeUI(root_obj_or_specific_one);

I had a similar problem and 2nd line solved the problem.

Marriageable answered 22/12, 2020 at 14:46 Comment(0)
F
0

Try this UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

Let me know if it works or not. :)

Flamethrower answered 12/10, 2015 at 16:4 Comment(1)
It didn't work. I already mention in my question that changing L&F didn't help. By the way, problem was somewhere in using Swing controls inside AWT dialog. I changed to Swing dialog and it worked. Thanks.Yon

© 2022 - 2024 — McMap. All rights reserved.