summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorDavid Gilbert <david.gilbert@object-refinery.com>2005-10-17 10:02:50 +0000
committerDavid Gilbert <david.gilbert@object-refinery.com>2005-10-17 10:02:50 +0000
commit844a0ae2a6b25d68cb12359b3c4b8dbf7456adb3 (patch)
tree96383df83c982c91cc5ffd1dbd2a7ff772579111 /examples
parente0b593e5c0fa1c86049e206d4fc21cd437141930 (diff)
downloadclasspath-844a0ae2a6b25d68cb12359b3c4b8dbf7456adb3.tar.gz
2005-10-17 David Gilbert <david.gilbert@object-refinery.com>
* examples/gnu/classpath/examples/swing/ComboBoxDemo.java: (CustomCellRenderer): new inner class, (comboState6): new field, (combo11): new field, (combo12): new field, (createContent): add panel from createPanel6(), (createPanel6): new method, (actionPerformed): update state for new JComboBoxes, * javax/swing/plaf/basic/BasicComboBoxUI.java (installComponents): don't create arrowButton until after listBox is created, set listBox to the JList created by the popup, * javax/swing/plaf/metal/MetalComboBoxButton.java: (MetalComboBoxButton(JComboBox, Icon, boolean, CellRendererPane, JList)): set margins to zero, (paintComponent): use list cell renderer to paint button content, * javax/swing/plaf/metal/MetalLookAndFeel.java (initComponentDefaults): add 'List.font' default.
Diffstat (limited to 'examples')
-rw-r--r--examples/gnu/classpath/examples/swing/ComboBoxDemo.java70
1 files changed, 69 insertions, 1 deletions
diff --git a/examples/gnu/classpath/examples/swing/ComboBoxDemo.java b/examples/gnu/classpath/examples/swing/ComboBoxDemo.java
index 24ae555d6..f9a89b048 100644
--- a/examples/gnu/classpath/examples/swing/ComboBoxDemo.java
+++ b/examples/gnu/classpath/examples/swing/ComboBoxDemo.java
@@ -24,6 +24,7 @@ package gnu.classpath.examples.swing;
import java.awt.BorderLayout;
import java.awt.Color;
+import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
@@ -31,12 +32,16 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
+import javax.swing.DefaultListCellRenderer;
+import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
+import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.UIManager;
+import javax.swing.plaf.metal.MetalIconFactory;
/**
* A simple demo showing various combo boxes in different states.
@@ -46,6 +51,24 @@ public class ComboBoxDemo
implements ActionListener
{
+ class CustomCellRenderer extends DefaultListCellRenderer
+ {
+ public Component getListCellRendererComponent(JList list,
+ Object value,
+ int index,
+ boolean isSelected,
+ boolean cellHasFocus)
+ {
+ DefaultListCellRenderer result = (DefaultListCellRenderer)
+ super.getListCellRendererComponent(list, value, index, isSelected,
+ cellHasFocus);
+ Icon icon = (Icon) value;
+ result.setIcon(icon);
+ result.setText("Index = " + index);
+ return result;
+ }
+ }
+
private JCheckBox comboState1;
private JComboBox combo1;
private JComboBox combo2;
@@ -66,6 +89,10 @@ public class ComboBoxDemo
private JComboBox combo9;
private JComboBox combo10;
+ private JCheckBox comboState6;
+ private JComboBox combo11;
+ private JComboBox combo12;
+
/**
* Creates a new demo instance.
*
@@ -80,12 +107,13 @@ public class ComboBoxDemo
private JPanel createContent()
{
JPanel content = new JPanel(new BorderLayout());
- JPanel panel = new JPanel(new GridLayout(5, 1));
+ JPanel panel = new JPanel(new GridLayout(6, 1));
panel.add(createPanel1());
panel.add(createPanel2());
panel.add(createPanel3());
panel.add(createPanel4());
panel.add(createPanel5());
+ panel.add(createPanel6());
content.add(panel);
JPanel closePanel = new JPanel();
JButton closeButton = new JButton("Close");
@@ -234,6 +262,41 @@ public class ComboBoxDemo
return panel;
}
+ /**
+ * This panel contains combo boxes with a custom renderer.
+ *
+ * @return A panel.
+ */
+ private JPanel createPanel6()
+ {
+ JPanel panel = new JPanel(new BorderLayout());
+ this.comboState6 = new JCheckBox("Enabled", true);
+ this.comboState6.setActionCommand("COMBO_STATE6");
+ this.comboState6.addActionListener(this);
+ panel.add(this.comboState6, BorderLayout.EAST);
+
+ JPanel controlPanel = new JPanel();
+ controlPanel.setBorder(BorderFactory.createTitledBorder("Custom Renderer: "));
+ this.combo11 = new JComboBox(new Object[] {
+ MetalIconFactory.getFileChooserHomeFolderIcon(),
+ MetalIconFactory.getFileChooserNewFolderIcon()});
+ this.combo11.setPreferredSize(new Dimension(100, 30));
+ this.combo11.setRenderer(new CustomCellRenderer());
+ this.combo12 = new JComboBox(new Object[] {
+ MetalIconFactory.getFileChooserHomeFolderIcon(),
+ MetalIconFactory.getFileChooserNewFolderIcon()});
+ this.combo12.setPreferredSize(new Dimension(100, 30));
+ this.combo12.setRenderer(new CustomCellRenderer());
+ this.combo12.setEditable(true);
+
+ controlPanel.add(combo11);
+ controlPanel.add(combo12);
+
+ panel.add(controlPanel);
+
+ return panel;
+ }
+
public void actionPerformed(ActionEvent e)
{
if (e.getActionCommand().equals("COMBO_STATE1"))
@@ -261,6 +324,11 @@ public class ComboBoxDemo
combo9.setEnabled(comboState5.isSelected());
combo10.setEnabled(comboState5.isSelected());
}
+ else if (e.getActionCommand().equals("COMBO_STATE6"))
+ {
+ combo11.setEnabled(comboState6.isSelected());
+ combo12.setEnabled(comboState6.isSelected());
+ }
else if (e.getActionCommand().equals("CLOSE"))
{
System.exit(0);