Java Swing组件
2018-01-09 19:23 更新
Java Swing教程 - Java Swing组件
滚动条值更改...
Java Swing组件继承自javax.swing.JComponent类和它充当所有Swing组件的基类。JComponent是一个抽象类。
JComponent
Java Swing组件继承自javax.swing.JComponent类和它充当所有Swing组件的基类。JComponent是一个抽象类。...
JComponent类作为所有Swing组件的基类,为所有Swing组件提供以下基本功能。
- tool tips
- pluggable look and feel
- border
- accessibility
- double buffering
- key binding
- laying out the component
JComponent方法
下表列出了JComponent的一些常用方法类可用于所有Swing组件。
-
Border getBorder()
Returns the border of the component or null if the component has no border. -
void setBorder(Border border)
Sets the border for the component. -
Object getClientProperty(Object key)
Returns the value associated with the specified key. The value must have been set using the putClientProperty (Object key, Object value) method. -
void putClientProperty(Object key, Object value)
Adds an arbitrary key-value pair to the component. -
Graphics getGraphics()
Returns the graphics context object for the component, which can be used to draw on the component. - Dimension getMaximumSize()
Dimension getMinimumSize()
Dimension getPreferredSize()
Dimension getSize(Dimension d)
void setMaximumSize(Dimension d)
void setMinimumSize(Dimension d)
void setPreferredSize(Dimension d)
void setSize(Dimension d)
void setSize(int width, int height)
Gets/sets the maximum, minimum, preferred, and actual size of the component. -
String getToolTipText()
Returns the tool tip text for this component. -
void setToolTipText(String text)
Sets the tool tip text. -
boolean isDoubleBuffered()
Returns true if the component uses double buffering. Otherwise, it returns false. -
void setDoubleBuffered(boolean db)
Sets if the component should use double buffering to paint or not. -
boolean isFocusable()
Returns true if the component can gain focus. Otherwise, it returns false. -
void setFocusable(boolean focusable)
Sets if the component can gain focus or not. -
boolean isVisible()
Returns true if the component is visible. Otherwise, it returns false. -
void setVisible(boolean v)
Sets the component visible or invisible. -
boolean isEnabled()
Returns true if the component is enabled. Otherwise, it returns false. -
void setEnabled(boolean e)
Enables or disables the component. - boolean requestFocus(boolean temporary)
boolean requestFocusInWindow()
boolean requestFocusInWindow(boolean temporary)
Both requestFocus() and requestFocusInWindow() methods request that the component should get the input focus.
We should use the requestFocusInWindow() method instead of the requestFocus() method because its behavior is consistent across all platforms. -
boolean isOpaque()
Returns true if the JComponent is opaque. Otherwise, it returns false. -
void setOpaque(boolean opaque)
Sets the opacity of the JComponent.
JComponent事件
下表列出了适用于所有Swing组件的一些常用事件。
- ComponentEvent/ComponentListener
The event occurs when a component"s visibility, size, or location is changed.
以上内容是否对您有帮助:
更多建议: