2012-09-14 32 views
1
public class ParserGUI extends javax.swing.JFrame { 
public ParserGUI() { 
     initComponents(); 
    } 
private void initComponents() { 
comText = new JTextArea(); 
internToggle = new javax.swing.JToggleButton(); 
comText = new javax.swing.JTextArea(); 
ComText.setColumns(20); 
ComText.setEditable(false); 
ComText.setRows(5); 
ComText.setLineWrap(true); 
ComText.setWrapStyleWord(true); 
ComText.setText(uids.toString()); // uids includes the UID's 

internToggle.setText("Nur interne"); 
     internToggle.addActionListener(new java.awt.event.ActionListener() { 
      public void actionPerformed(java.awt.event.ActionEvent evt) { 
       InternToggleActionPerformed(evt); 
      } 
     }); 

private void internToggleActionPerformed(ActionEvent evt) { 
     System.out.println("Intern"); 
    if (externToggle.isSelected()) { 
     externToggle.setSelected(false); 
    } 

    if (internToggle.isSelected()) { 
     String[] person = comText.getText().split("; "); 
     StringBuffer newPerson = new StringBuffer(); 
     for (String string : person) { 
      if (string.matches("((?i)u)([0-9]{6})")) { 
       newPerson.append(string + "; "); 
      } 
     } 
     comText.setText(newPerson.toString()); 
     } 
    } 

public static void main(String args[]) { 
     /* 
     * Set the Nimbus look and feel 
     */ 
     // <editor-fold defaultstate="collapsed" 
     // desc=" Look and feel setting code (optional) "> 
     /* 
     * If Nimbus (introduced in Java SE 6) is not available, stay with the 
     * default look and feel. For details see 
     * http://download.oracle.com/javase 
     * /tutorial/uiswing/lookandfeel/plaf.html 
     */ 
     try { 
      for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager 
        .getInstalledLookAndFeels()) { 
       if ("Nimbus".equals(info.getName())) { 
        javax.swing.UIManager.setLookAndFeel(info.getClassName()); 
        break; 
       } 
      } 
     } catch (ClassNotFoundException ex) { 
      java.util.logging.Logger.getLogger(ParserGUI.class.getName()).log(
        java.util.logging.Level.SEVERE, null, ex); 
     } catch (InstantiationException ex) { 
      java.util.logging.Logger.getLogger(ParserGUI.class.getName()).log(
        java.util.logging.Level.SEVERE, null, ex); 
     } catch (IllegalAccessException ex) { 
      java.util.logging.Logger.getLogger(ParserGUI.class.getName()).log(
        java.util.logging.Level.SEVERE, null, ex); 
     } catch (javax.swing.UnsupportedLookAndFeelException ex) { 
      java.util.logging.Logger.getLogger(ParserGUI.class.getName()).log(
        java.util.logging.Level.SEVERE, null, ex); 
     } 
     // </editor-fold> 

     /* 
     * Create and display the form 
     */ 
     java.awt.EventQueue.invokeLater(new Runnable() { 

      public void run() { 
       new ParserGUI().setVisible(true); 
      } 
     }); 
    } 

    // Variables declaration - do not modify 
    private javax.swing.JTextArea comText; 
    private javax.swing.JToggleButton internToggle; 
    // End of variables declaration 

我想通過單擊JToggleButton (internToggle)來更新我的JTextArea (comText)。 但是,當我點擊按鈕,沒有任何改變。使用JToggleButton更新JTextArea

我在SO和谷歌搜索,但所有的解決方案都不能在我的程序中工作。

Programm應該做些什麼:
我的TextArea包含很多不同的用戶ID uids.toString()

示例內容:u100125; u100149; u100187; u100364; u110207; u110318; u111949; u112850; u114345; u117205; u118421; u119058; u123362; u128621; u143754; u147190; u149220; u149788; u149911; u160017; u160081; u161927; u162659; u163383; u165021; u165363; u165534; u165765; u166052; u166731; u166912; u200965; u201334; u201942; u202144; u202291; u202293; u202544; u202670; u202899; u202920; u202928; u202975; u203103; u203271; u203499; u203739; u203960; u204011; u204030; u204333; u204652; u205166; u205203; u205420; u205595; u206596; u206741; u207063; u207455; u207467; u207627; u207742; u207788; u207797; u208344; u208419; u208637; u208820; u209382; u209903; u210041; u210690; u210767; u210854; u210875; u212119; u213175; u213517; u213940; ue01545; ue03732; ue05728; ue06895; ue53655; ue54224; ue55155; ue55385; ue57760; ue58142;

現在我想篩選出來自UE-ID的的U-ID與切換按鈕。

我的方法internToggleActionPerformed的作品。 newPerson()包含所有的u-ID。 但TextArea什麼都不做。我如何更新TextArea

+0

向我們展示textarea的示例內容。 – basiljames

+2

請發表一個完整的代碼。我們不是猜測大師! –

+0

不知道我是否正確,但是您使用您的過濾結果覆蓋了您的JTextArea的內容,並且您還從JTextArea()讀取以獲取過濾的輸入 - 因此,當按下切換按鈕兩次時,你正在過濾已經過濾的文本,不是嗎? –

回答

1

完成了。

這是我的Eclipse的錯。在我的公司,我們有一個帶有我們自己的插件的Eclipse。新版本使用GIT,但我自己的小項目是使用SVN開發的,該插件有問題。因此,我的所有GUI應用程序都已啓動,但隨後凍結。

無論如何,謝謝你的大力幫助!

+0

問題:我該如何關閉***這個問題......? :) –

+1

+1用於回報:-)不需要關閉任何東西 - 接受你自己的答案,所以其他有類似問題的人可以很快看到它 – kleopatra

+2

好的,完成了。再次感謝你的幫助 :) –

1

使用此tutorial

  1. 根據兩個切換按鈕編寫一個打印文本到控制檯的小程序。
  2. 一旦你看到打印到來,添加一個文本區域,並將文本也設置到文本區域。
  3. 一旦這也工作添加您的正則表達式分析。
2

我已將您的代碼片段包裝到可運行的應用程序中,請參閱http://pastebin.com/S2A3drXk。它按預期工作,沒有各種調用來驗證()/ repaint()/ pack()。我建議以此爲出發點,並逐步修改它,直到添加完所有附加代碼。

聲明:我非常瞭解Java命名約定。我的意圖是使用與OP相同的偵聽器,並且我將它留給OP來熟悉Java命名和編碼約定並適當地應用它們。

+0

它可以它不會更新我的程序中,因爲佈局? 我使用javax.swing.GroupLayout –

+0

不,我從上面拿走了更新的代碼並添加了一個簡單的GroupLayout,請參閱http://pastebin.com/K4igVfGv。它也可以。再次,我的建議,類似於@basiljames:以一個已知工作的例子爲例,比如我發佈的兩個包含我自己的樣本之一,並檢查它是否可以修改。然後通過添加代碼來逐步修改它。您將自動到達不再工作的地步:) –

+0

您可以編輯您的答案以包含代碼。 – trashgod