Oct 28, 2009

New Substance - old problems!

A new release (5.3) still useless for me. The unresolved issues with SwingX components prevent from using this well looking and features rich LnF in my projects. Some screen-shots are below. I have created a simple application to demonstrate issues with SwibgX (1.0) components under Substance (5.3) LnF. First of all JXErrorPane while resizing run out of screen. It looks really ugly. Secondly JXTable looks absolutely different of JTable. Here is the source code to reproduce the behavior depicted above.
package javatabletest;

import java.awt.GridLayout;
import java.awt.HeadlessException;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.table.DefaultTableModel;
import org.jdesktop.swingx.JXErrorPane;
import org.jdesktop.swingx.JXTable;
import org.jvnet.substance.skin.SubstanceBusinessLookAndFeel;

public class Main {

    static class MyTableModel extends DefaultTableModel {

        public MyTableModel(Object[][] data, Object[] columnNames) {
            super(data, columnNames);
        }

        @Override
        public Class<?> getColumnClass(int columnIndex) {
            return (columnIndex == 4)?Boolean.class:Object.class;
        }

    }

    static Vector createDataVector(int id, String n, boolean a){
        Vector v = new Vector();
        v.add(id);
        v.add(n);
        v.add(a);
        return v;
    }

    public static void main(String[] args) {

        SwingUtilities.invokeLater(new Runnable() {

            public void run() {
                try {
                    UIManager.setLookAndFeel(new SubstanceBusinessLookAndFeel());
                } catch (UnsupportedLookAndFeelException ex) {
                    Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
                }
                JFrame.setDefaultLookAndFeelDecorated(true);
                JDialog.setDefaultLookAndFeelDecorated(true);
                JXErrorPane.showDialog(new Exception());
                createUI();
            }
        });
    }

    private static void createUI() throws HeadlessException {
        JFrame frame = new JFrame("Table test");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        String[] columnNames = {"First Name",
                                "Last Name",
                                "Sport",
                                "# of Years",
                                "Vegetarian"};

        Object[][] data = {
            {"Mary", "Campione",
             "Snowboarding", new Integer(5), new Boolean(false)},
            {"Alison", "Huml",
             "Rowing", new Integer(3), new Boolean(true)},
            {"Kathy", "Walrath",
             "Knitting", new Integer(2), new Boolean(false)},
            {"Sharon", "Zakhour",
             "Speed reading", new Integer(20), new Boolean(true)},
            {"Philip", "Milne",
             "Pool", new Integer(10), new Boolean(false)}
        };


        MyTableModel model = new MyTableModel(data, columnNames);
        JTable table1 = new JTable(model);

        JTable table2 = new JXTable(model);

        JPanel panel = new JPanel(new GridLayout(2, 1));

        JScrollPane pane1 = new JScrollPane(table1);
        JScrollPane pane2 = new JScrollPane(table2);

        panel.add(pane1);
        panel.add(pane2);
        panel.setOpaque(true);

        frame.setContentPane(panel);
        frame.pack();
        frame.setVisible(true);
    }
}

No comments: