Swing JButton在Solaris上无法正确渲染,使用Java 8。

7
我已经从我的Windows机器连接到Solaris 11。我已将DISPLAY设置为我的机器,并使用Java 8。
注意:在使用Java 6时,这个方法是有效的。
当我启动对话框时,它的按钮和其他Swing组件无法呈现。
观察到它可以在以下环境下工作:
o Windows 7 Enterprise
o Windows Server 2012 Enterprise
我尝试更改 L&F 但没有起作用。当我使用 "GTKLookAndFeel" 时,按钮出现了,但没有文本或标签。
非常感谢任何帮助。如果需要进一步的阐述,请告诉我。谢谢。
我的对话框代码如下:
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

}

当你说“我已将DISPLAY设置为我的机器”时,不清楚你所指的机器是什么。考虑到你写道你不知道Solaris机器是否为无头状态,我假设你没有在Solaris上渲染swing按钮,而是(间接地)渲染到其他地方。你在Windows机器上运行X11服务器吗? - jlliagre
请确切地说明您正在使用哪个 Solaris 更新/ sru(pkg info kernel | grep FMRI),以及这是哪个精确的 jvm(java -version)。 - jlliagre
2
你为什么在Swing对话框中使用java.awt.Dialog而不是javax.swing.JDialog - Holger
@Holger 感谢您的观察和发现。这个问题从我的视线中溜走了。这是一个旧组件,使用了各种AWT类。将其移动到Swing Dialog上在Solaris机器上运行良好。不过,我们已经推荐使用Windows Server 2012发布了我们的产品,这时候实际上有点晚了。虽然使用Swing对话框可以解决问题,但问题仍然存在:为什么AWT对话框一开始就没有工作?尽管如此,您肯定值得奖励!非常感谢…… - Rahul Winner
@Holger 上面只是我写的一个示例代码,在实际代码中,已经导入了包,因此没有使用完全限定名称。但在这里使用完全限定名称让我们捕获到了它。 - Rahul Winner
显示剩余2条评论
2个回答

1

要应用外观效果,您需要提供两个命令:

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

我遇到了类似的问题,第二行解决了问题。

0
尝试这个 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
告诉我它是否有效。 :)

它没有起作用。我在我的问题中已经提到更改L&F没有帮助。 顺便说一下,问题出在在AWT对话框中使用Swing控件上。我改为使用Swing对话框,它就可以工作了。 谢谢。 - Rahul Winner

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接