
- Swing 教程
- Swing - 首頁
- Swing - 概述
- Swing - 環境
- Swing - 控制元件
- Swing - 事件處理
- Swing - 事件類
- Swing - 事件監聽器
- Swing - 事件介面卡
- Swing - 佈局
- Swing - 選單
- Swing - 容器
- Swing 有用資源
- Swing - 快速指南
- Swing - 有用資源
- Swing - 討論
Swing - JComponent 類
介紹
類JComponent是除頂級容器之外所有Swing元件的基類。要使用繼承自JComponent的元件,必須將其放置在以頂級Swing容器為根的容器層次結構中。
類宣告
以下是javax.swing.JComponent類的宣告:
public abstract class JComponent extends Container implements Serializable
欄位
以下是java.awt.Component類的欄位:
protected AccessibleContext accessibleContext - 與此JComponent關聯的AccessibleContext。
protected EventListenerList listenerList - 此元件的事件監聽器列表。
static String TOOL_TIP_TEXT_KEY - 當游標位於元件上方時顯示的註釋,也稱為“值提示”、“懸停幫助”或“懸停標籤”。
protected ComponentUI ui - 此元件的外觀和感覺委託。
static int UNDEFINED_CONDITION - 一些API使用此常量表示未定義任何條件。
static int WHEN_ANCESTOR_OF_FOCUSED_COMPONENT - 用於registerKeyboardAction的常量,表示當接收元件是焦點元件的祖先或其自身是焦點元件時,應呼叫該命令。
static int WHEN_FOCUSED - 用於registerKeyboardAction的常量,表示當元件具有焦點時,應呼叫該命令。
static int WHEN_IN_FOCUSED_WINDOW - 用於registerKeyboardAction的常量,表示當接收元件位於具有焦點的視窗中或其自身是焦點元件時,應呼叫該命令。
類建構函式
序號 | 建構函式和描述 |
---|---|
1 |
JComponent() 預設JComponent建構函式。 |
類方法
序號 | 方法和描述 |
---|---|
1 |
void addAncestorListener(AncestorListener listener) 註冊監聽器,以便當它或其任何祖先移動或可見或不可見時,它將接收AncestorEvents。 |
2 |
void addNotify() 通知此元件它現在具有父元件。 |
3 |
void addVetoableChangeListener(VetoableChangeListener listener) 向監聽器列表新增VetoableChangeListener。 |
4 |
void computeVisibleRect(Rectangle visibleRect) 返回元件的“可見矩形” - 此元件及其所有祖先的可見矩形的交集。 |
5 |
boolean contains(int x, int y) 為UI委託提供一個機會來定義此元件的精確形狀,以便進行滑鼠處理。 |
6 |
JToolTip createToolTip() 返回應用於顯示工具提示的JToolTip例項。 |
7 |
void disable() 已棄用。自JDK版本1.1起,已由java.awt.Component.setEnabled(boolean)替代。 |
8 |
void enable() 已棄用。自JDK版本1.1起,已由java.awt.Component.setEnabled(boolean)替代。 |
9 |
void firePropertyChange(String propertyName, boolean oldValue, boolean newValue) 支援為布林屬性報告繫結屬性更改。 |
10 |
void firePropertyChange(String propertyName, char oldValue, char newValue) 報告繫結屬性更改。 |
11 |
void firePropertyChange(String propertyName, int oldValue, int newValue) 支援為整數屬性報告繫結屬性更改。 |
12 |
protected void fireVetoableChange(String propertyName, Object oldValue, Object newValue) 支援報告受約束的屬性更改。 |
13 |
AccessibleContext getAccessibleContext() 返回與此JComponent關聯的AccessibleContext。 |
14 |
ActionListener getActionForKeyStroke(KeyStroke aKeyStroke) 返回將對給定擊鍵執行操作的物件。 |
15 |
ActionMap getActionMap() 返回用於確定對特定KeyStroke繫結觸發哪個Action的ActionMap。 |
16 |
float getAlignmentX() 覆蓋Container.getAlignmentX以返回垂直對齊方式。 |
17 |
float getAlignmentY() 覆蓋Container.getAlignmentY以返回水平對齊方式。 |
18 |
AncestorListener[]getAncestorListeners() 返回在此元件上註冊的所有祖先監聽器的陣列。 |
19 |
boolean getAutoscrolls() 獲取autoscrolls屬性。 |
20 |
int getBaseline(int width, int height) 返回基線。 |
21 |
Component.BaselineResizeBehavior getBaselineResizeBehavior() 返回一個列舉,指示元件的基線如何隨大小變化而變化。 |
22 |
Border getBorder() 返回此元件的邊框,如果當前未設定邊框,則返回null。 |
23 |
Rectangle getBounds(Rectangle rv) 將此元件的邊界儲存到“返回值”rv中並返回rv。 |
24 |
Object getClientProperty(Object key) 返回具有指定鍵的屬性的值。 |
25 |
protected Graphics getComponentGraphics(Graphics g) 返回用於繪製此元件的圖形物件。 |
26 |
JPopupMenu getComponentPopupMenu() 返回為此元件分配的JPopupMenu。 |
27 |
int getConditionForKeyStroke(KeyStroke aKeyStroke) 返回確定是否註冊的操作響應指定的擊鍵而發生的條件。 |
28 |
int getDebugGraphicsOptions() 返回圖形除錯的狀態。 |
29 |
static Locale getDefaultLocale() 返回用於在建立時初始化每個JComponent的locale屬性的預設區域設定。 |
30 |
FontMetrics getFontMetrics(Font font) 獲取指定字型的FontMetrics。 |
31 |
Graphics getGraphics() 返回此元件的圖形上下文,允許您在元件上繪製。 |
32 |
int getHeight() 返回此元件的當前高度。 |
33 |
boolean getInheritsPopupMenu() 如果JPopupMenu應從父級繼承,則返回true。 |
34 |
InputMap getInputMap() 返回元件具有焦點時使用的InputMap。 |
35 |
InputMap getInputMap(int condition) 返回在條件期間使用的InputMap。 |
36 |
InputVerifier getInputVerifier() 返回此元件的輸入驗證器。 |
37 |
Insets getInsets() 如果在此元件上設定了邊框,則返回邊框的內邊距;否則呼叫super.getInsets。 |
38 |
Insets getInsets(Insets insets) 返回一個Insets物件,其中包含此元件的內邊距值。 |
39 |
<T extends EventListener> T[] getListeners(Class<T> listenerType) 返回當前在此JComponent上註冊為FooListeners的所有物件的陣列。 |
40 |
Point getLocation(Point rv) 將此元件的x,y原點儲存到“返回值”rv中並返回rv。 |
41 |
Dimension getMaximumSize() 如果最大大小已設定為非null值,則直接返回它。 |
42 |
Dimension getMinimumSize() 如果最小大小已設定為非null值,則直接返回它。 |
43 |
Component getNextFocusableComponent() 已棄用。自1.4起,已由FocusTraversalPolicy替代。 |
44 |
Point getPopupLocation(MouseEvent event) 返回在此元件的座標系中顯示彈出選單的首選位置。 |
45 |
Dimension getPreferredSize() 如果preferredSize已設定為非null值,則直接返回它。 |
46 |
KeyStroke[] getRegisteredKeyStrokes() 返回將啟動註冊操作的KeyStrokes。 |
47 |
JRootPane getRootPane() 返回此元件的JRootPane祖先。 |
48 |
Dimension getSize(Dimension rv) 將此元件的寬度/高度儲存到“返回值”rv中並返回rv。 |
49 |
Point getToolTipLocation(MouseEvent event) 返回此元件座標系中的工具提示位置。 |
50 |
String getToolTipText() 返回已使用setToolTipText設定的工具提示字串。 |
51 |
String getToolTipText(MouseEvent event) 返回用作事件工具提示的字串。 |
52 |
Container getTopLevelAncestor() 返回此元件的頂級祖先(包含的視窗或Applet),如果此元件未新增到任何容器中,則返回null。 |
53 |
TransferHandler getTransferHandler() 獲取transferHandler屬性。 |
54 |
String getUIClassID() 返回用於查詢定義此元件外觀和感覺的swing.plaf.ComponentUI類名稱的UIDefaults鍵。 |
55 |
boolean getVerifyInputWhenFocusTarget() 返回一個值,該值指示在當前焦點所有者請求焦點之前是否會呼叫當前焦點所有者的輸入驗證器。 |
56 |
VetoableChangeListener[] getVetoableChangeListeners() 返回在此元件上註冊的所有可否決更改偵聽器的陣列。 |
57 |
Rectangle getVisibleRect() 返回元件的“可見矩形” - 此元件的可見矩形、new rectangle(0, 0, getWidth(), getHeight())及其所有祖先的可見矩形的交集。 |
58 |
int getWidth() 返回此元件的當前寬度。 |
59 |
int getX() 返回元件原點的當前x座標。 |
60 |
int getY() 返回元件原點的當前y座標。 |
61 |
void grabFocus() 請求此元件獲取輸入焦點,並將此元件的頂級祖先設為焦點視窗。 |
62 |
boolean isDoubleBuffered() 返回此元件是否應使用緩衝區進行繪製。 |
63 |
static boolean isLightweightComponent(Component c) 如果此元件是輕量級的,即它沒有本機視窗系統對等體,則返回true。 |
64 |
boolean isManagingFocus() 已棄用。自1.4起,已由Component.setFocusTraversalKeys(int, Set)和Container.setFocusCycleRoot(boolean)替代。 |
65 |
boolean isOpaque() 如果此元件完全不透明,則返回true。 |
66 |
boolean isOptimizedDrawingEnabled() 如果此元件平鋪其子元件,即它可以保證子元件不會重疊,則返回true。 |
67 |
boolean isPaintingForPrint() 如果此元件上的當前繪圖操作是列印操作的一部分,則返回true。 |
68 |
boolean isPaintingTile() 如果元件當前正在繪製圖塊,則返回true。 |
69 |
boolean isRequestFocusEnabled() 如果此JComponent應獲得焦點,則返回true;否則返回false。 |
70 |
boolean isValidateRoot() 如果此方法返回true,則此元件的後代呼叫的revalidate將導致從該根開始的整個樹都被驗證。 |
71 |
void paint(Graphics g) 由Swing呼叫以繪製元件。 |
72 |
protected void paintBorder(Graphics g) 繪製元件的邊框。 |
73 |
protected void paintChildren(Graphics g) 繪製此元件的子元件。 |
74 |
protected void paintComponent(Graphics g) 如果UI委託非空,則呼叫UI委託的paint方法。 |
75 |
void paintImmediately(int x, int y, int w, int h) 立即繪製此元件及其與該區域重疊的所有後代的指定區域。 |
76 |
void paintImmediately(Rectangle r) 立即繪製指定的區域。 |
77 |
protected String paramString() 返回此JComponent的字串表示形式。 |
78 |
void print(Graphics g) 呼叫此方法將元件列印到指定的Graphics。 |
79 |
void printAll(Graphics g) 呼叫此方法列印元件。 |
80 |
protected void printBorder(Graphics g) 列印元件的邊框。 |
81 |
protected void printChildren(Graphics g) 列印此元件的子元件。 |
82 |
protected void printComponent(Graphics g) 在列印操作期間呼叫此方法。 |
83 |
protected void processComponentKeyEvent(KeyEvent e) 處理元件本身識別的任何鍵盤事件。 |
84 |
protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed) 呼叫此方法處理ks的鍵繫結,這是KeyEvent e的結果。 |
85 |
protected void processKeyEvent(KeyEvent e) 重寫processKeyEvent以處理事件。 |
86 |
protected void processMouseEvent(MouseEvent e) 透過將滑鼠事件分派給任何已註冊的MouseListener物件來處理在此元件上發生的滑鼠事件,有關此方法的完整描述,請參閱Component.processMouseEvent(MouseEvent)。 |
87 |
protected void processMouseMotionEvent(MouseEvent e) 處理滑鼠移動事件,例如MouseEvent.MOUSE_DRAGGED。 |
88 |
void putClientProperty(Object key, Object value) 向此元件新增任意鍵/值“客戶端屬性”。 |
89 |
void registerKeyboardAction(ActionListener anAction, KeyStroke aKeyStroke, int aCondition) 此方法現已過時,請使用getActionMap()和getInputMap()的組合來實現類似的行為。 |
90 |
void registerKeyboardAction(ActionListener anAction, String aCommand, KeyStroke aKeyStroke, int aCondition) 此方法現已過時,請使用getActionMap()和getInputMap()的組合來實現類似的行為。 |
91 |
void removeAncestorListener(AncestorListener listener) 登出監聽器,使其不再接收AncestorEvents。 |
92 |
void removeNotify() 通知此元件它不再具有父元件。 |
93 |
void removeVetoableChangeListener(VetoableChangeListener listener) 從監聽器列表中移除VetoableChangeListener。 |
94 |
void repaint(long tm, int x, int y, int width, int height) 如果元件正在顯示,則將指定的區域新增到髒區域列表。 |
95 |
void repaint(Rectangle r) 如果元件正在顯示,則將指定的區域新增到髒區域列表。 |
96 |
boolean requestDefaultFocus() 已棄用。從 1.4 開始,已由FocusTraversalPolicy.getDefaultComponent(Container).requestFocus()取代。 |
97 |
void requestFocus() 請求此元件獲取輸入焦點。 |
98 |
boolean requestFocus(boolean temporary) 請求此元件獲取輸入焦點。 |
99 |
boolean requestFocusInWindow() 請求此元件獲取輸入焦點。 |
100 |
protected boolean requestFocusInWindow(boolean temporary) 請求此元件獲取輸入焦點。 |
101 |
void resetKeyboardActions() 登出第一層InputMaps和ActionMap中的所有繫結。 |
102 |
void reshape(int x, int y, int w, int h) 已棄用。從JDK 5開始,已由Component.setBounds(int, int, int, int)取代。移動並調整此元件的大小。 |
103 |
void revalidate() 支援延遲自動佈局。 |
104 |
void scrollRectToVisible(Rectangle aRect) 將scrollRectToVisible()訊息轉發到JComponent的父級。 |
105 |
void setActionMap(ActionMap am) 將ActionMap設定為am。 |
106 |
void setAlignmentX(float alignmentX) 設定垂直對齊方式。 |
107 |
void setAlignmentY(float alignmentY) 設定水平對齊方式。 |
108 |
void setAutoscrolls(boolean autoscrolls) 設定autoscrolls屬性。 |
109 |
void setBackground(Color bg) 設定此元件的背景顏色。 |
110 |
void setBorder(Border border) 設定此元件的邊框。 |
111 |
void setComponentPopupMenu(JPopupMenu popup) 為這個JComponent設定JPopupMenu。 |
112 |
void setDebugGraphicsOptions(int debugOptions) 啟用或停用有關在元件或其子元件中執行的每個圖形操作的診斷資訊。 |
113 |
static void setDefaultLocale(Locale l) 設定用於在建立時初始化每個JComponent的locale屬性的預設語言環境。 |
114 |
void setDoubleBuffered(boolean aFlag) 設定此元件是否應使用緩衝區進行繪製。 |
115 |
void setEnabled(boolean enabled) 設定此元件是否啟用。 |
116 |
void setFocusTraversalKeys(int id, Set<? extends AWTKeyStroke> keystrokes) 為此元件的給定遍歷操作設定焦點遍歷鍵。 |
117 |
void setFont(Font font) 設定此元件的字型。 |
118 |
void setForeground(Color fg) 設定此元件的前景色。 |
119 |
void setInheritsPopupMenu(boolean value) 設定getComponentPopupMenu是否應委託給父級(如果此元件沒有分配JPopupMenu)。 |
120 |
void setInputMap(int condition, InputMap map) 設定在condition條件下使用的InputMap進行對映。 |
121 |
void setInputVerifier(InputVerifier inputVerifier) 設定此元件的輸入驗證器。 |
122 |
void setMaximumSize(Dimension maximumSize) 將此元件的最大大小設定為常數值。 |
123 |
void setMinimumSize(Dimension minimumSize) 將此元件的最小大小設定為常數值。 |
124 |
void setNextFocusableComponent(Component aComponent) 已棄用。從 1.4 開始,已由FocusTraversalPolicy取代。 |
125 |
void setOpaque(boolean isOpaque) 如果為true,則元件在其邊界內繪製每個畫素。 |
126 |
void setPreferredSize(Dimension preferredSize) 設定此元件的首選大小。 |
127 |
void setRequestFocusEnabled(boolean requestFocusEnabled) 提供關於此JComponent是否應該獲取焦點的提示。 |
128 |
void setToolTipText(String text) 註冊在工具提示中顯示的文字。 |
129 |
void setTransferHandler(TransferHandler newHandler) 設定transferHandler屬性,如果元件不支援資料傳輸操作,則為null。 |
130 |
protected void setUI(ComponentUI newUI) 設定此元件的外觀和感覺委託。 |
131 |
void setVerifyInputWhenFocusTarget(boolean verifyInputWhenFocusTarget) 設定值以指示在當前焦點所有者的輸入驗證器是否在該元件請求焦點之前被呼叫。 |
132 |
void setVisible(boolean aFlag) 使元件可見或不可見。 |
133 |
void unregisterKeyboardAction(KeyStroke aKeyStroke) 此方法現已過時。 |
134 |
void update(Graphics g) 呼叫paint。 |
135 |
void updateUI() 將UI屬性重置為當前外觀和感覺的值。 |
繼承的方法
此類繼承自以下類的方法:
- java.awt.Container
- java.awt.Component
- java.lang.Object