1

[SOLVED]: I have Lenovo Z500 notebook, which use it's own video driver for Intel HD 4000. I use this driver because of it interacts with hotkeys on my laptop keyboard (F11, F12 for screen brightness). I tested compiled JAR file on my second Dell laptop and everything works fine! If you have any problems with rendering Swing elements on your Lenovo laptop with Lenovo pre-installed drivers, you have to install native Intel driver.

===

I made a Swing application using Windows L&F, but after Run (compile) i see wrong rendering elements. BUT! when i use preview, everything looks OK. Here's some screens of bugs (i think):

Left side: Preview Right side: Run Mode

Preview Mode Run mode

As you can see on the right picture, we have a thick line (like duplicate) on a left side of each element (including jTextField, jComboBox, jSpinner and others) except Buttons in Run Mode. Does anybody know what's a problem? Somebody said in here that it's problems with video card driver, but what exactly should i do to fix this problem?

  • System: Winodows 8.1
  • NetBeans: 8.0
  • Java SDK: 1.8.0_11

Thank's ahead for any answers!

Full source code goes below:

public static void main(String args[]) {

    try {
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Windows".equals(info.getName())) {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (ClassNotFoundException ex) {
        java.util.logging.Logger.getLogger(mainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(mainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(mainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(mainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
    //</editor-fold>

    /* Create and display the form */
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            new mainWindow().setVisible(true);
        }
    });
}

GUI elements generated by NetBeans:

private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jComboBox1 = new javax.swing.JComboBox();
        jTextField1 = new javax.swing.JTextField();
        jSpinner1 = new javax.swing.JSpinner();
        jProgressBar1 = new javax.swing.JProgressBar();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("Button");

        jButton1.setText("jButton1");

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jProgressBar1.setMinimum(1);
        jProgressBar1.setValue(25);
        jProgressBar1.setStringPainted(true);

        jLabel2.setText("ComboBox");

        jLabel3.setText("TextField");

        jLabel4.setText("Spinner");

        jLabel5.setText("ProgressBar");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jComboBox1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jTextField1)
                    .addComponent(jProgressBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 181, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButton1)
                            .addComponent(jSpinner1, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jButton1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jSpinner1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jProgressBar1, jSpinner1});

        pack();
    }
obohovyk
  • 482
  • 2
  • 5
  • 12
  • 2
    Please edit your question to include a [minimal, complete example](http://stackoverflow.com/help/mcve) that exhibits the problem you describe. Your use of a GUI editor at this stage in development may be a problem; _minimal_ would exclude any generated code, yet _complete_ enough for someone with your setup to run. – trashgod Nov 29 '14 at 12:28
  • `for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Windows".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; }}` So Windows PLAF for Windows and bugger the rest? And by 'bugger the rest' I mean leave OS X and Linux/Unix to see ..Metal (shudder). Why not instead `UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());`? The resulting PLAF would be Windows 7 for Windows, Aqua for OS X and GTK or CDE/Motif for Linux & Unix based systems. – Andrew Thompson Nov 29 '14 at 12:58
  • @AndrewThompson, i tried you way but everything looks the same ( Here's code example: `public static void main(String args[]) throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException {` `UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());` `...` – obohovyk Nov 29 '14 at 13:06
  • *"but everything looks the same"* ..do you **use Windows**? (checks screenshots, of course you do). The point is it will look different (to the default Metal PLAF) on OS X and Linux/Unix! – Andrew Thompson Nov 29 '14 at 13:08
  • @AndrewThompson, of course! You can see it in my first post: System: Winodows 8.1 – obohovyk Nov 29 '14 at 13:09
  • Check the screenshots in [this answer](http://stackoverflow.com/a/5630271/418556) (ignoring the one in Nimbus PLAF) for how the system PLAF might look on [Mac. (OS X)](http://i.stack.imgur.com/Jaqap.png) and [Ubuntu with GTK+](http://i.stack.imgur.com/521zz.png).. Don't forget: This is Java, so don't just code for Windows machines! – Andrew Thompson Nov 29 '14 at 13:13
  • I understand, but this problem appers only on Windows 8.1. Everything looks great on CentOS 7 under GTK+. – obohovyk Nov 29 '14 at 13:23

1 Answers1

2

Using Windows 8.1 Pro, with JRE 1.8.0_25, i see no problem in the rendered gui, here is my screenshot:

enter image description here

Naruto Biju Mode
  • 2,011
  • 3
  • 15
  • 28
  • Hm.. really strange ) I have Windows 8.1 SL, but the result differs from yours... Can you tell me what video card do you have? – obohovyk Nov 29 '14 at 14:20
  • @alexkowalski I have a cheap video card: Mobile Intel(R) 4 Series Express Chipset Family – Naruto Biju Mode Nov 29 '14 at 14:24
  • I found a problem! I have Lenovo Z500 notebook, which use it's own video driver for Intel HD 4000. I use this driver because of it interacts with hotkeys on my laptop keyboard (F5, F6 etc.). I tested this compiled JAR file on my second Dell laptop and everything works fine! Great! Thank you for you testing and helping me, i thought it wasn't my local problem! – obohovyk Nov 29 '14 at 14:42