Hi,

I have noticed a few issues in the Gtk Look and Feel and would like to know what the correct behaviour should be. The attached program shows a few of my concerns.

1) For each of the components, setForeground(color) and/or setBackground(color) assignments are randomly ignored. Is this the expected behaviour? I can understand that using the native look and feel, the feel is exactly preserved and the programmer's preferences are ignored. But there doesn't seem to be any consistency - some components accept the color changes, some silently ignore it. Is there a list showing whether setForeground() and setBackground() is ignored for each swing component with the gtk look and feel?

2) The behaviour varies across jdk6 and openjdk6. For example, the closed-source jdk6 respects JTextPane.setBackground(UIManager.getColor("Panel.background")) but openjdk6 ignores it. In situations like this, what is the correct behaviour? Should I attempt to patch openjdk6 to behave more like closed source jdk6?

Thanks,

Omair
import java.awt.Color;
import java.awt.Container;
import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.UIManager;
import javax.swing.WindowConstants;

public class TestGtkBackground {

    private static JFrame window = new JFrame("Gtk Window");

    public static void createGui() {

        Container contentPane = window.getContentPane();
        contentPane.setLayout(new GridLayout(5, 1));

        JButton button = new JButton("JButton: Blue Background with Magenta Text");
        button.setForeground(Color.MAGENTA);
        button.setBackground(Color.BLUE);
        contentPane.add(button);

        JComboBox comboBox = new JComboBox(
                new Object[] { "JComboBox: Red foreground", "Green Background" });
        comboBox.setForeground(Color.RED);
        comboBox.setBackground(Color.GREEN);
        contentPane.add(comboBox);

        JTextArea textArea = new JTextArea("JTextArea: Gray Foreground, pink background");
        textArea.setForeground(Color.GRAY);
        textArea.setBackground(Color.PINK);
        contentPane.add(textArea);

        JTextField textField = new JTextField("JTextField: White foreground, yellow background");
        textField.setBackground(Color.WHITE);
        textField.setBackground(Color.YELLOW);
        contentPane.add(textField);

        
        JTextPane textPane = new JTextPane();
        textPane.setText("JTextPane: Green foreground, 'panel.background' background");
        textPane.setForeground(Color.green);
        textPane.setBackground(UIManager.getColor("Panel.background"));
        contentPane.add(textPane);
        
        
        window.pack();
        window.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        window.setVisible(true);

    }

    public static void main(String[] args) {

        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) {
            e.printStackTrace();
        }

        createGui();

    }

}

<<inline: sun-jdk.png>>

<<inline: openjdk6.png>>

Reply via email to