Java Tutorial/Swing/UIManager

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

14. Active UIResources

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ActiveSample {
  private static final String LABEL_FACTORY = "LabelFactory";
  public static void main (String args[]) {
        JFrame frame = new JFrame("Active Example");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        UIManager.put(LABEL_FACTORY, new ActiveLabel());
        final JPanel panel = new JPanel();
        JButton button = new JButton("Get");
        ActionListener actionListener = new ActionListener() {
          public void actionPerformed(ActionEvent actionEvent) {
            JLabel label = (JLabel)UIManager.get(LABEL_FACTORY);
            panel.add(label);
            panel.revalidate();
          }
        };
        button.addActionListener(actionListener);
        frame.add(panel, BorderLayout.CENTER);
        frame.add(button, BorderLayout.SOUTH);
        frame.setSize(200, 200);
        frame.setVisible(true);
  }
}





14. Lazy UIResources

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.ruponent;
import java.awt.Graphics;
import java.awt.Polygon;
import javax.swing.Icon;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
public class LazySample {
  public static void main(String args[]) {
    JFrame frame = new JFrame("Lazy Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Integer fifteen = new Integer(15);
    Object lazyArgs[] = new Object[] { Color.GREEN, Boolean.TRUE, fifteen, fifteen };
    Object lazyDiamond = new UIDefaults.ProxyLazyValue("MyIcon", lazyArgs);
    UIManager.put("Tree.openIcon", lazyDiamond);
    JTree tree = new JTree();
    JScrollPane scrollPane = new JScrollPane(tree);
    frame.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(200, 200);
    frame.setVisible(true);
  }
}
class MyIcon implements Icon {
  public MyIcon(Object obj) {
  }
  public int getIconHeight() {
    return 20;
  }
  public int getIconWidth() {
    return 20;
  }
  public void paintIcon(Component c, Graphics g, int x, int y) {
    g.setColor(Color.RED);
    g.fillRect(1,1,20,20);
  }
}





14. Retrieve information of all available UIManager defaults

import javax.swing.LookAndFeel;
import javax.swing.UIManager;
public class Main {
  public static void main(String[] args) {
    System.out.println("  " + UIManager.getLookAndFeel().getName());
    UIManager.LookAndFeelInfo[] inst = UIManager.getInstalledLookAndFeels();
    for (int i = 0; i < inst.length; i++) {
      System.out.println("  " + inst[i].getName());
    }
    LookAndFeel[] aux = UIManager.getAuxiliaryLookAndFeels();
    if (aux != null) {
      for (int i = 0; i < aux.length; i++) {
        System.out.println("  " + aux[i].getName());
      }
    } else {
      System.out.println("  <NONE>");
    }
    System.out.println("  " + UIManager.getCrossPlatformLookAndFeelClassName());
    System.out.println("  " + UIManager.getSystemLookAndFeelClassName());
  }
}





14. UIResource Collection

UIResource ImplementationWrapped Class/InterfaceActionMapUIResourceActionMapBasicBorders.ButtonBorderBorderBasicBorders.FieldBorderBorderBasicBorders.MarginBorderBorderBasicBorders.MenuBarBorderBorderBasicBorders.RadioButtonBorderBorderBasicBorders.RolloverButtonBorderBorderBasicBorders.SplitPaneBorderBorderBasicBorders.ToggleButtonBorderBorderBasicComboBoxEditor.UIResourceComboBoxEditorBasicComboBoxRenderer.UIResourceListCellRendererBasicTextUI.BasicCaretCaretBasicTextUI.BasicHighlighterHighlighterBorderUIResourceBorderBorderUIResource.BevelBorderUIResourceBorderBorderUIResource.rupoundBorderUIResourceBorderBorderUIResource.EmptyBorderUIResourceBorderBorderUIResource.EtchedBorderUIResourceBorderBorderUIResource.LineBorderUIResourceBorderBorderUIResource.MatteBorderUIResourceBorderBorderUIResource.TitledBorderUIResourceBorderColorUIResourceColorComponentInputMapUIResourceInputMap / ComponentInputMapDefaultListCellRenderer.UIResourceListCellRendererDefaultMenuLayoutLayoutManager / LayoutManager2DefaultTableCellRenderer.UIResourceTableCellRendererDimensionUIResourceDimensionFontUIResourceFontIconUIResourceIconInputMapUIResourceInputMapInsetsUIResourceInsetsJScrollPane.ScrollBarJScrollBarMetalBorders.ButtonBorderBorderMetalBorders.Flush3DBorderBorderMetalBorders.InternalFrameBorderBorderMetalBorders.MenuBarBorderBorderMetalBorders.MenuItemBorderBorderMetalBorders.OptionDialogBorderBorderMetalBorders.PaletteBorderBorderMetalBorders.PopupMenuBorderBorderMetalBorders.RolloverButtonBorderBorderMetalBorders.ScrollPaneBorderBorderMetalBorders.TextFieldBorderBorderMetalBorders.ToggleButtonBorderBorderMetalBorders.ToolBarBorderBorderMetalCheckBoxIconIconMetalComboBoxEditor.UIResourceComboBoxEditorMetalIconFactory.PaletteCloseIconIconScrollPaneLayout.UIResourceScrollPaneLayout