我不知道爲什麼我的JTextField沒有被點擊時啓用。無法啓用按鈕點擊JTextField
這裏就是我創建並設置JTextField中的代碼:
PromptHandler ph = new PromptHandler(this);
textPanel = new JPanel();
arEntry = new JTextField(REGION_TEXT_FIELD_COLUMNS);
arEntry.setToolTipText(ENTER_NEW_REGION_ID_TITLE_TEXT);
arEntry.setActionCommand(ENTER_NEW_REGION_ID_TITLE_TEXT);
arEntry.addActionListener(ph);
textPanel.add(arEntry);
這裏是在PromptHandler,是以文本字段的照顧代碼:
private HelloWorld hwApp;
private String id;
public PromptHandler (HelloWorld hw) {
hwApp = hw;
}
@Override
public void actionPerformed(ActionEvent ae) {
String command = ae.getActionCommand();
switch(command) {
case ENTER_NEW_REGION_ID_TITLE_TEXT:
hwApp.arEntry.setEnabled(true);
break;
如果您以前調用過'arEntry.setEnabled(false)',那麼如何調用'actionPerformed()'? – trashgod 2013-02-14 00:19:51
你如何監視鼠標事件的字段? – MadProgrammer 2013-02-14 00:22:21