package widget.plaf.concrete; import java.awt.*; import javax.swing.*; import javax.swing.border.*; import javax.swing.plaf.*; import widget.*; import widget.plaf.*; public class CComboPaneUI extends ComboPaneUI { protected ComboPane pane; protected JComboBox[] comboBoxes; public static ComponentUI createUI(JComponent c) { return new CComboPaneUI(); } public void installUI(JComponent c) { this.pane = (ComboPane)c; pane.setOpaque(false); pane.setLayout(new GridBagLayout()); pane.setBorder(new EmptyBorder(10, 10, 10, 10)); int numCombos = pane.getNumCombos(); comboBoxes = new JComboBox[numCombos]; for (int i = 0; i < numCombos; i++) { // Add the label. JLabel label = new JLabel(pane.getLabel(i) + ": ", JLabel.RIGHT); addComponent(pane, label, 0, i, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, GridBagConstraints.CENTER); // Add the combo box. comboBoxes[i] = new JComboBox(pane.getModel(i)); addComponent(pane, comboBoxes[i], 1, i, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, GridBagConstraints.CENTER); } } /** * Adapted from O'Reilly's Java AWT Reference, p. 276, */ public static void addComponent(Container container, Component component, int gridx, int gridy, int gridwidth, int gridheight, double weightx, double weighty, int fill, int anchor) { GridBagLayout gbl = (GridBagLayout)container.getLayout(); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = gridx; gbc.gridy = gridy; gbc.gridwidth = gridwidth; gbc.gridheight = gridheight; gbc.weightx = weightx; gbc.weighty = weighty; gbc.fill = fill; gbc.anchor = anchor; gbl.setConstraints(component, gbc); container.add(component); } public void uninstallUI(JComponent c) { } }