Java Tutorial/Swing/UI Delegate

Материал из Java эксперт
Перейти к: навигация, поиск

14. Creating a New UI Delegate

Swing Component        Class ID String         Implementation Class
JButton                ButtonUI                ButtonUI
JCheckBox              CheckBoxUI              ButtonUI
JCheckBoxMenuItem      CheckBoxMenuItemUI      MenuItemUI
JColorChooser          ColorChooserUI          ColorChooserUI
JComboBox              ComboBoxUI              ComboBoxUI
JComponent             n/a                     ComponentUI
JDesktopPane           DesktopPaneUI           DesktopPaneUI
JEditorPane            EditorPaneUI            TextUI
JFileChooser           FileChooserUI           FileChooserUI
JFormattedTextField    FormattedTextFieldUI    TextUI
JInternalFrame         InternalFrameUI         InternalFrameUI
JInternalFrame.JDesktopIcon DesktopIconUI      DesktopIconUI
JLabel                 LabelUI                 LabelUI
JList                  ListUI                  ListUI
JMenu                  MenuUI                  MenuItemUI
JMenuBar               MenuBarUI               MenuBarUI
JMenuItem              MenuItemUI              MenuItemUI
JOptionPane            OptionPaneUI            OptionPaneUI
JPanel                 PanelUI                 PanelUI
JPasswordField         PasswordFieldUI         TextUI
JPopupMenu             PopupMenuUI             PopupMenuUI
JPopupMenu.Separator   PopupMenuSeparatorUI    SeparatorUI
JProgressBar           ProgressBarUI           ProgressBarUI
JRadioButton           RadioButtonUI           ButtonUI
JRadioButtonMenuItem   RadioButtonMenuItemUI   MenuItemUI
JRootPane              RootPaneUI              RootPaneUI
JScrollBar             ScrollBarUI             ScrollBarUI
JScrollPane            ScrollPaneUI            ScrollPaneUI
JSeparator             SeparatorUI             SeparatorUI
JSlider                SliderUI                SliderUI
JSpinner               SpinnerUI               SpinnerUI
JSplitPane             SplitPaneUI             SplitPaneUI
JTabbedPane            TabbedPaneUI            TabbedPaneUI
JTable                 TableUI                 TableUI
JTableHeader           TableHeaderUI           TableHeaderUI
JTextArea              TextAreaUI              TextUI
JTextField             TextFieldUI             TextUI
JTextPane              TextPaneUI              TextUI
JToggleButton          ToggleButtonUI          ButtonUI
JToolBar               ToolBarUI               ToolBarUI
JToolBar.Separator     ToolBarSeparatorUI      SeparatorUI
JToolTip               ToolTipUI               ToolTipUI
JTree                  TreeUI                  TreeUI
JViewport              ViewportUI              ViewportUI





14. Using Customized ComboBoxUI

import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.plaf.ruboBoxUI;
import javax.swing.plaf.ruponentUI;
import javax.swing.plaf.basic.BasicArrowButton;
import javax.swing.plaf.basic.BasicComboBoxUI;
class MyComboBoxUI extends BasicComboBoxUI {
  public static ComponentUI createUI(JComponent c) {
    return new MyComboBoxUI();
  }
  protected JButton createArrowButton() {
    JButton button = new BasicArrowButton(BasicArrowButton.EAST);
    return button;
  }
}
public class PopupComboSample {
  public static void main(String args[]) {
    String labels[] = { "A", "B", "C", "D" };
    JFrame frame = new JFrame("Popup JComboBox");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JComboBox comboBox = new JComboBox(labels);
    comboBox.setUI((ComboBoxUI) MyComboBoxUI.createUI(comboBox));
    frame.add(comboBox, BorderLayout.NORTH);
    JComboBox comboBox2 = new JComboBox(labels);
    frame.add(comboBox2, BorderLayout.SOUTH);
    frame.setSize(300, 100);
    frame.setVisible(true);
  }
}