Java Tutorial/Swing/Client Property — различия между версиями

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

Текущая версия на 15:31, 31 мая 2010

14. Client Property

Each instance of every component can manage its own set of key/value pairs.



public final void putClientProperty(Object key, Object value)
public final Object getClientProperty(Object key)





14. Swing"s Client Properties Summary Table

Class Accessed By            Property Name                        Type
AbstractButton               hideActionText                       Boolean
AbstractButton               html / BasicHTML.propertyKey         View
BasicButtonListener          initialDefaultButton                 JButton
BasicButtonUI                html / BasicHTML.propertyKey         View
BasicComboBoxUI              JComboBox.isTableCellEditor /        Boolean
                             BasicComboBoxUI.IS_TABLE_CELL_EDITOR
  
BasicEditorPaneUI            JEditorPane.honorDisplayProperties / Boolean
                             JEditorPane.HONOR_DISPLAY_PROPERTIES
BasicEditorPaneUI            JEditorPane.w3cLengthUnits /         Boolean
                             JEditorPane.W3C_LENGTH_UNITS
  
BasicHTML                    html.base /                          URL
                             BasicHTML.documentBaseKey
  
BasicHTML                    html / BasicHTML.propertyKey         View
BasicHTML                    html.disable /                       Boolean
                             BasicHTML.htmlDisable
BasicLabelUI                 html / BasicHTML.propertyKey         View
BasicListUI                  List.isFileList                      Boolean
BasicMenuItemUI              html / BasicHTML.propertyKey         View
BasicMenuItemUI              maxTextWidth /                       Integer
                             BasicMenuItemUI.MAX_TEXT_WIDTH
BasicMenuItemUI              maxAccWidth /                        Integer
                             BasicMenuItemUI.MAX_ACC_WIDTH
  
BasicPopupMenuUI             doNotCancelPopup                     Boolean
BasicRadioButtonUI           html / BasicHTML.propertyKey         View
BasicRootPaneUI              temporaryDefaultButton               Object
BasicSliderUI                Slider.paintThumbArrowShape          Boolean
BasicTabbedPaneUI            __index_to_remove__                  Integer
BasicTableUI                 Table.isFileList                     Boolean
BasicTextUI                  JPasswordField.cutCopyAllowed        Boolean
BasicToggleButtonUI          html / BasicHTML.propertyKey         View
BasicToolBarUI               JToolBar.focusedCompIndex /          Integer
                             BasicToolBarUI. FOCUSED_COMP_INDEX
  
BasicToolBarUI               JToolBar.isRollover /                Boolean
                             BasicToolBarUI. IS_ROLLOVER
  
BasicToolTipUI               html / BasicHTML.propertyKey         View
BluePrintEngine              __arrow_direction__                  Integer
DefaultCaret                 caretAspectRatio                     Number
DefaultCaret                 caretWidth                           Integer
DefaultCaret                 JPasswordField.cutCopyAllowed        Boolean
DefaultDesktopManager        JDesktopPane.dragMode                String; valid values are null, outline, and faster
FrameView                    charset                              String
GTKFileChooserUI             GTKFileChooser.showDirectoryIcons    Boolean
GTKFileChooserUI             GTKFileChooser.showFileIcons         Boolean
JInternalFrame               wasIconOnce /                        Boolean 
                             DefaultDesktopManager.HAS_BEEN_ICONIFIED_PROPERTY
JComponent                   nextFocus / JComponent.NEXT_FOCUS    Component
JComponent                   InputVerifier /                      InputVerifier
                             JComponent.INPUT_VERIFIER_KEY
  
JComponent                   _WhenInFocusedWindow /               Hashtable
                             JComponent.WHEN_IN_FOCUSED_WINDOW_BINDINGS
JComponent                   ToolTipText /                        String
                             JComponent.TOOL_TIP_TEXT_KEY
JComponent                   TransferHandler /                    TransferHandler
                             JComponent.TRANSFER_HANDLER_KEY
JComponent                   AncestorNotifier /                   AncestorNotifier
                             JComponent.ANCESTOR_NOTIFIER_KEY
  
JComponent                   labeledBy /                          JComponent / Accessible
                             JLabel.LABELED_BY_PROPERTY
  
JEditorPane                  charset          String
JLabel                       html / BasicHTML.propertyKey         View
JLayeredPane                 layeredContainerLayer /              Integer
                             JLayeredPane.LAYER_PROPERTY
  
JPasswordField               JPasswordField.cutCopyAllowed        Boolean
JPopupMenu                   JPopupMenu.firePopupMenuCanceled     Boolean
JTable                       JTable.autoStartsEdit                Boolean
JTable                       terminateEditOnFocusLost             Boolean
JToolBar                     JToolBar.isRollover                  Boolean
MetalBorders                 NoButtonRollover /                   Boolean
                             MetalBorders.NO_BUTTON_ROLLOVER
MetalBorders                 JInternalFrame.messageType           Integer
MetalFileChooserUI           FileChooser.useShellFolder           Boolean
MetalIconFactory             paintActive                          Boolean
MetalInternalFrame TitlePane JInternalFrame.messageType           Integer
MetalInternalFrameUI         JInternalFrame.isPalette /           Boolean
                             MetalInternalFrameUI.IS_PALETTE
MetalRadioButtonUI           html / BasicHTML.propertyKey         View
MetalScrollBarUI             JScrollBar.isFreeStanding /          Boolean
                             MetalScrollBarUI.FREE_STANDING_PROP
  
MetalSliderUI                JSlider.isFilled /                   Boolean
                             MetalSliderUI.SLIDER_FILL
MetalTreeUI                  JTree.lineStyle /                    String; valid values are Angled (MetalTreeUI. LEG_LINE_STYLE_STRING), Horizontal (MetalTreeUI .HORIZ_STYLE_STRING), and None (MetalTreeUI. NO_STYLE_STRING)
                             MetalTreeUI.LineStyle
MotifGraphicsUtils           html / BasicHTML.propertyKey         View
MotifGraphicsUtils           maxAccWidth /                        Integer
                             MotifGraphicsUtils.MAX_ACC_WIDTH
PopupFactory                 __force_heavy_weight_popup__ /       Boolean
                             PopupFactory.forceHeavyWeightPopupKey
SpringLayout                 SpringLayout.class                   SpringLayout. Constraints
SwingUtilities               html / BasicHTML.propertyKey         View
SynthEditorPaneUI            JEditorPane.honorDisplayProperties / Boolean 
                             JEditorPane.HONOR_DISPLAY_PROPERTIES
SynthGraphicUtils            html / BasicHTML.propertyKey         View
SynthMenuItemUI              html / BasicHTML.propertyKey         View
SynthToolTipUI               html / BasicHTML.propertyKey         View
WindowsDesktopManager        JInternalFrame.frameType             String; valid values are null and optionDialog
WindowsFileChooserUI         FileChooser.useShellFolder           Boolean
WindowsSliderUI              Slider.paintThumbArrowShape          Boolean
WindowsToolBarUI             XPStyle.subclass                     String





14. Using JTree client property: Produce horizontal lines between level-one nodes

import java.awt.BorderLayout;
import java.awt.Color;
import java.util.Vector;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.UIManager;
class TreeNodeVector<E> extends Vector<E> {
  String name;
  TreeNodeVector(String name) {
    this.name = name;
  }
  TreeNodeVector(String name, E elements[]) {
    this.name = name;
    for (int i = 0, n = elements.length; i < n; i++) {
      add(elements[i]);
    }
  }
  public String toString() {
    return "[" + name + "]";
  }
}
public class ChangingTreeLineStyleColorHorizontal {
  public static void main(final String args[]) {
    JFrame frame = new JFrame("JTreeSample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Vector<String> v1 = new TreeNodeVector<String>("Two", new String[] { "Mercury", "Venus",
        "Mars" });
    Vector<Object> v2 = new TreeNodeVector<Object>("Three");
    v2.add(System.getProperties());
    v2.add(v1);
    Object rootNodes[] = {v1, v2 };
    Vector<Object> rootVector = new TreeNodeVector<Object>("Root", rootNodes);
    JTree tree = new JTree(rootVector);
    UIManager.put("Tree.line", Color.GREEN);
    tree.putClientProperty("JTree.lineStyle", "Horizontal");
    
    frame.add(new JScrollPane(tree), BorderLayout.CENTER);
    frame.setSize(300, 300);
    frame.setVisible(true);
    
  }
}