📄 jcomponent.java
字号:
/** * <p>Whether to double buffer this component when painting. This flag * should generally be <code>true</code>, to ensure good painting * performance.</p> * * <p>All children of a double buffered component are painted into the * double buffer automatically, so only the top widget in a window needs * to be double buffered.</p> * * @see #setDoubleBuffered * @see #isDoubleBuffered * @see #paint */ boolean doubleBuffered = true; /** * A set of flags indicating which debugging graphics facilities should * be enabled on this component. The values should be a combination of * {@link DebugGraphics#NONE_OPTION}, {@link DebugGraphics#LOG_OPTION}, * {@link DebugGraphics#FLASH_OPTION}, or {@link * DebugGraphics#BUFFERED_OPTION}. * * @see #setDebugGraphicsOptions * @see #getDebugGraphicsOptions * @see DebugGraphics * @see #getComponentGraphics */ int debugGraphicsOptions; /** * <p>This property controls two independent behaviors simultaneously.</p> * * <p>First, it controls whether to fill the background of this widget * when painting its body. This affects calls to {@link * JComponent#paintComponent}, which in turn calls {@link * ComponentUI#update} on the component's {@link #ui} property. If the * component is opaque during this call, the background will be filled * before calling {@link ComponentUI#paint}. This happens merely as a * convenience; you may fill the component's background yourself too, * but there is no need to do so if you will be filling with the same * color.</p> * * <p>Second, it the opaque property informs swing's repaint system * whether it will be necessary to paint the components "underneath" this * component, in Z-order. If the component is opaque, it is considered to * completely occlude components "underneath" it, so they will not be * repainted along with the opaque component.</p> * * <p>The default value for this property is <code>false</code>, but most * components will want to set it to <code>true</code> when installing UI * defaults in {@link ComponentUI#installUI}.</p> * * @see #setOpaque * @see #isOpaque * @see #paintComponent */ boolean opaque = false; /** * The user interface delegate for this component. Event delivery and * repainting of the component are usually delegated to this object. * * @see #setUI * @see #getUIClassID * @see #updateUI */ protected ComponentUI ui; /** * A hint to the focus system that this component should or should not * get focus. If this is <code>false</code>, swing will not try to * request focus on this component; if <code>true</code>, swing might * try to request focus, but the request might fail. Thus it is only * a hint guiding swing's behavior. * * @see #requestFocus() * @see #isRequestFocusEnabled * @see #setRequestFocusEnabled */ boolean requestFocusEnabled; /** * Flag indicating behavior of this component when the mouse is dragged * outside the component and the mouse <em>stops moving</em>. If * <code>true</code>, synthetic mouse events will be delivered on regular * timed intervals, continuing off in the direction the mouse exited the * component, until the mouse is released or re-enters the component. * * @see #setAutoscrolls * @see #getAutoscrolls */ boolean autoscrolls = false; /** * Indicates whether the current paint call is already double buffered or * not. */ static boolean isPaintingDoubleBuffered = false; /** * Listeners for events other than {@link PropertyChangeEvent} are * handled by this listener list. PropertyChangeEvents are handled in * {@link #changeSupport}. */ protected EventListenerList listenerList = new EventListenerList(); /** * Support for {@link PropertyChangeEvent} events. This is constructed * lazily when the component gets its first {@link * PropertyChangeListener} subscription; until then it's an empty slot. */ private SwingPropertyChangeSupport changeSupport; /** * Storage for "client properties", which are key/value pairs associated * with this component by a "client", such as a user application or a * layout manager. This is lazily constructed when the component gets its * first client property. */ private Hashtable clientProperties; private InputMap inputMap_whenFocused; private InputMap inputMap_whenAncestorOfFocused; private ComponentInputMap inputMap_whenInFocusedWindow; private ActionMap actionMap; /** @since 1.3 */ private boolean verifyInputWhenFocusTarget; private InputVerifier inputVerifier; private TransferHandler transferHandler; /** * Indicates if this component is currently painting a tile or not. */ private boolean paintingTile; /** * A cached Rectangle object to be reused. Be careful when you use that, * so that it doesn't get modified in another context within the same * method call chain. */ private static transient Rectangle rectCache; /** * The default locale of the component. * * @see #getDefaultLocale * @see #setDefaultLocale */ private static Locale defaultLocale; public static final String TOOL_TIP_TEXT_KEY = "ToolTipText"; /** * Constant used to indicate that no condition has been assigned to a * particular action. * * @see #registerKeyboardAction(ActionListener, KeyStroke, int) */ public static final int UNDEFINED_CONDITION = -1; /** * Constant used to indicate that an action should be performed only when * the component has focus. * * @see #registerKeyboardAction(ActionListener, KeyStroke, int) */ public static final int WHEN_FOCUSED = 0; /** * Constant used to indicate that an action should be performed only when * the component is an ancestor of the component which has focus. * * @see #registerKeyboardAction(ActionListener, KeyStroke, int) */ public static final int WHEN_ANCESTOR_OF_FOCUSED_COMPONENT = 1; /** * Constant used to indicate that an action should be performed only when * the component is in the window which has focus. * * @see #registerKeyboardAction(ActionListener, KeyStroke, int) */ public static final int WHEN_IN_FOCUSED_WINDOW = 2; /** * Indicates if this component is completely dirty or not. This is used * by the RepaintManager's * {@link RepaintManager#isCompletelyDirty(JComponent)} method. */ boolean isCompletelyDirty = false; /** * Creates a new <code>JComponent</code> instance. */ public JComponent() { super(); super.setLayout(new FlowLayout()); setDropTarget(new DropTarget()); defaultLocale = Locale.getDefault(); debugGraphicsOptions = DebugGraphics.NONE_OPTION; setRequestFocusEnabled(true); } /** * Helper to lazily construct and return the client properties table. * * @return The current client properties table * * @see #clientProperties * @see #getClientProperty * @see #putClientProperty */ private Hashtable getClientProperties() { if (clientProperties == null) clientProperties = new Hashtable(); return clientProperties; } /** * Get a client property associated with this component and a particular * key. * * @param key The key with which to look up the client property * * @return A client property associated with this object and key * * @see #clientProperties * @see #getClientProperties * @see #putClientProperty */ public final Object getClientProperty(Object key) { return getClientProperties().get(key); } /** * Add a client property <code>value</code> to this component, associated * with <code>key</code>. If there is an existing client property * associated with <code>key</code>, it will be replaced. A * {@link PropertyChangeEvent} is sent to registered listeners (with the * name of the property being <code>key.toString()</code>). * * @param key The key of the client property association to add * @param value The value of the client property association to add * * @see #clientProperties * @see #getClientProperties * @see #getClientProperty */ public final void putClientProperty(Object key, Object value) { Hashtable t = getClientProperties(); Object old = t.get(key); if (value != null) t.put(key, value); else t.remove(key); firePropertyChange(key.toString(), old, value); } /** * Unregister an <code>AncestorListener</code>. * * @param listener The listener to unregister * * @see #addAncestorListener */ public void removeAncestorListener(AncestorListener listener) { listenerList.remove(AncestorListener.class, listener); } /** * Unregister a <code>PropertyChangeListener</code>. * * @param listener The listener to register * * @see #addPropertyChangeListener(PropertyChangeListener) * @see #changeSupport */ public void removePropertyChangeListener(PropertyChangeListener listener) { if (changeSupport != null) changeSupport.removePropertyChangeListener(listener); } /** * Unregister a <code>PropertyChangeListener</code>. * * @param propertyName The property name to unregister the listener from * @param listener The listener to unregister * * @see #addPropertyChangeListener(String, PropertyChangeListener) * @see #changeSupport */ public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) { if (changeSupport != null) changeSupport.removePropertyChangeListener(propertyName, listener); } /** * Unregister a <code>VetoableChangeChangeListener</code>. * * @param listener The listener to unregister * * @see #addVetoableChangeListener */ public void removeVetoableChangeListener(VetoableChangeListener listener) { listenerList.remove(VetoableChangeListener.class, listener); } /** * Register an <code>AncestorListener</code>. * * @param listener The listener to register * * @see #removeVetoableChangeListener */ public void addAncestorListener(AncestorListener listener) { listenerList.add(AncestorListener.class, listener); } /** * Register a <code>PropertyChangeListener</code>. This listener will * receive any PropertyChangeEvent, regardless of property name. To * listen to a specific property name, use {@link * #addPropertyChangeListener(String,PropertyChangeListener)} instead. * * @param listener The listener to register * * @see #removePropertyChangeListener(PropertyChangeListener) * @see #changeSupport */ public void addPropertyChangeListener(PropertyChangeListener listener) { if (changeSupport == null) changeSupport = new SwingPropertyChangeSupport(this); changeSupport.addPropertyChangeListener(listener); } /** * Register a <code>PropertyChangeListener</code> for a specific, named * property. To listen to all property changes, regardless of name, use * {@link #addPropertyChangeListener(PropertyChangeListener)} instead. * * @param propertyName The property name to listen to * @param listener The listener to register * * @see #removePropertyChangeListener(String, PropertyChangeListener) * @see #changeSupport */ public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) { listenerList.add(PropertyChangeListener.class, listener); } /** * Register a <code>VetoableChangeListener</code>. * * @param listener The listener to register * * @see #removeVetoableChangeListener * @see #listenerList */ public void addVetoableChangeListener(VetoableChangeListener listener) { listenerList.add(VetoableChangeListener.class, listener); } /** * Return all registered listeners of a particular type. * * @param listenerType The type of listener to return * * @return All listeners in the {@link #listenerList} which * are of the specified type * * @see #listenerList */ public EventListener[] getListeners(Class listenerType) { return listenerList.getListeners(listenerType); } /** * Return all registered <code>AncestorListener</code> objects. * * @return The set of <code>AncestorListener</code> objects in {@link * #listenerList} */ public AncestorListener[] getAncestorListeners() { return (AncestorListener[]) getListeners(AncestorListener.class); } /** * Return all registered <code>VetoableChangeListener</code> objects. * * @return The set of <code>VetoableChangeListener</code> objects in {@link * #listenerList} */ public VetoableChangeListener[] getVetoableChangeListeners() { return (VetoableChangeListener[]) getListeners(VetoableChangeListener.class); } /** * Return all <code>PropertyChangeListener</code> objects registered to listen * for a particular property. * * @param property The property to return the listeners of * * @return The set of <code>PropertyChangeListener</code> objects in * {@link #changeSupport} registered to listen on the specified property */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -