2011-08-02 31 views
1
public Action colorAction = new AbstractAction("Font Color", new ImageIcon(
     getClass().getResource("/img/color.png"))) { 
    public void actionPerformed(ActionEvent e) { 
     colorB_actionPerformed(e); 
    } 
}; 

public void colorB_actionPerformed(ActionEvent e) { 
    Color c = JColorChooser.showDialog(getRightPanel(), "Font color", 
      Color.CYAN); 
    if (c == null) 
     return; 
    new StyledEditorKit.ForegroundAction("", c).actionPerformed(e); 
} 

以上是我用來顯示顏色選擇器對話框的代碼。我的問題是,我從來沒有開始運行或編譯程序。但顏色選擇器對話框會自動出現?Swing JDialog框出現嗎?

public void linkActionB_actionPerformed(ActionEvent e) { 
    String value = JOptionPane.showInputDialog(getJPanel(), "Enter URL :"); 

    String aTag = "<a"; 
    aTag += " href=\"" + value + "\""; 

    aTag += ">" + value + "</a>"; 
    if (editor.getCaretPosition() == document.getLength()) 
     aTag += "&nbsp;"; 
    editor.replaceSelection(""); 
    try { 
     editorKit.insertHTML(document, editor.getCaretPosition(), aTag, 0, 
       0, HTML.Tag.A); 
    } catch (Exception ex) { 
     ex.printStackTrace(); 
    } 
} 

以及顯示鏈接對話框也會自動出現,當我還在編碼時。任何想法?

+0

我使用eclipse可視化編輯器打開它。這是正常的,如果用可視化編輯器打開,那麼對話框會自動彈出?因爲當我用java編輯器打開它時,對話框不會彈出。 – user236501

回答

2

是的,我敢打賭,您正在使用某種IDE,並且您還有一些過去運行或調試會話仍處於活動狀態。檢查並關閉所有正在運行/調試的JVM,並從新開始。

+0

嗨,謝謝你回覆,我重新啓動Eclipse IDE,一旦我打開文件對話框將出現甚至沒有開始運行或編譯文件 – user236501

+0

你有一個autorun設置的地方?事情不只是運行,必須開始。 –

+0

如果在Windows中工作,請轉至任務管理器並殺死所有找到的java進程。比啓動Eclipse IDE –