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

I want update my JTextArea (comText) with a click on the JToggleButton (internToggle). But when i click on the button, nothing changed.

I search in SO and in google, but all of the solutions doesn't work in my program.

What The Programm should do:
My TextArea contains a lot of different User-ID's uids.toString().

Example-Content: 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;

Now I want to filter out the u-ID's from the ue-ID's with the toggle Button.

My method internToggleActionPerformed works. newPerson() contains all u-ID's. But the TextArea do nothing. How can I update the TextArea?

Michael Schmidt
  • 9,090
  • 13
  • 56
  • 80
  • Show us the sample contents of your textarea. – basiljames Sep 14 '12 at 09:01
  • 2
    Please, post a complete code. We are not guessing gurus! – Guillaume Polet Sep 14 '12 at 09:02
  • Dont know if I get it right, but you are overwriting the contents of your JTextArea with your filtered result, and you are also reading from the JTextArea() to get the input for your filtering - so, when pressing the toggle button twice, you are filtering the already filtered text, dont you? – Andreas Fester Sep 14 '12 at 09:04
  • @andreas: yes, but i wanna fix this after the method works... :) – Michael Schmidt Sep 14 '12 at 09:06
  • @Guillaume Polet: now i post the full method. i don't hope you need the full code... or what do you additionally need? – Michael Schmidt Sep 14 '12 at 09:07
  • @dTDesign So, it does not even work for the first time? Means, you have "u123456; u234567; ue12345" and it is not updated to "u123456; u234567" as expected? – Andreas Fester Sep 14 '12 at 09:09
  • @Andreas: When i try the method with the debugger out, it works. but the textarea-content doesn't change... – Michael Schmidt Sep 14 '12 at 09:11
  • @dTDesign Means, newPerson contains the correct value, but the setText() call does not have any effect? – Andreas Fester Sep 14 '12 at 09:13
  • @Andreas: Yes. newPerson contains only the filtered u-Numbers, but the method does not change anything in the textArea... – Michael Schmidt Sep 14 '12 at 09:15
  • Please learn java naming conventions and stick to them. BTW, random method calling will _never_ solve a problem - even if it seems to be solved after some abstruse combination, it's still there only smeared over ;-) In particular, none of re/in/validate/repaint is necessary when changing a component property and updateUI is **not** for usage in application code at all. – kleopatra Sep 14 '12 at 09:21
  • @kleopatra: do you mean the name of the JTextArea? This is a auto-generated code by NetBeans UI Creator... i can't (and won't) change it... what do you mean with "smeared over" ? so it's great when i doesn't need this methods... but i don't know how i should realize it!... – Michael Schmidt Sep 14 '12 at 09:31
  • -1 I'm quite certain that netbeans doesn't create names which violate naming conventions ... show an SSCCE (google if you don't know what that is) as has been already suggested by @GuillaumePolet if you really want help. – kleopatra Sep 14 '12 at 09:35
  • so i add the new code. sorry, it's one of my first post, and i just started with java development... – Michael Schmidt Sep 14 '12 at 09:48
  • 1
    it's okay to make mistakes at the beginning (we all did and still do, plenty :-) It's not okay to not follow advice given, repeatedly :-( Your next steps to get help and rid of my downvote: a) find out what SSCCE is b) implement that and replace your snippets with the SSCCE. And while/before typing in any names (that's _you_ not your IDE :-) read the chapter on naming conventions .. (hint: mainly boils down to start method/field names with a lower-case letter) – kleopatra Sep 14 '12 at 09:58
  • Your variable names alone make the code very difficult to debug. – basiljames Sep 14 '12 at 10:21
  • so i update my question. hope it's ok now... and thank you for your help and patience kleopatra :) – Michael Schmidt Sep 14 '12 at 10:48

3 Answers3

2

I have wrapped your code fragments into a runnable application, see http://pastebin.com/S2A3drXk. It works as expected, without the various calls to validate()/repaint()/pack(). I suggest to use this as a starting point and modify it step by step until you have added all your additional code.

Disclaimer: I very well know the Java naming conventions. My intention was to use the same listener as the OP, and I leave it up to the OP to get familiar with the Java naming and coding conventions and apply them appropriately.

Andreas Fester
  • 36,091
  • 7
  • 95
  • 123
  • can it be that it don't update in my programm because the layout? i use the javax.swing.GroupLayout – Michael Schmidt Sep 14 '12 at 11:08
  • No. I took your updated code from above and added a simple GroupLayout, see http://pastebin.com/K4igVfGv. It also works. Again my advice, similar as from @basiljames: Take an example which is known to work, like one of my two self containing samples I posted, and check if it works unmodified. Then modify it step by step by adding your code. You will automatically come to the point where it does not work anymore :) – Andreas Fester Sep 14 '12 at 11:58
  • @trashgod: is there any limit on the size of code snippets? Did not find anything in the FAQs, and I was not sure if it is fine to add a rather large listing directly into the answer, thats why I choose pastebin ... – Andreas Fester Sep 14 '12 at 12:36
  • 2
    @Andreas: Good question. I don't know the technological limit, but I try to keep an [sscce](http://sscce.org/) to ~100 lines. The [longest](http://codereview.stackexchange.com/q/4446) I've seen is ~600. – trashgod Sep 14 '12 at 13:23
  • 1
    @Andreas: Empirically, I just found out the limit is 30,000 characters. – trashgod Sep 20 '12 at 02:44
1

Use this tutorial.

  1. Write a small program printing a text to console based on two toggle buttons.
  2. Once you see the print coming, add a text area and set the text into the text area also.
  3. Once that is also working add your regex parsing.
basiljames
  • 4,777
  • 4
  • 24
  • 41
1

It's done.

It was a fault of my Eclipse. In my Company, we've an Eclipse with our own Plugins. The new Versions use GIT, but my small own Project was developed with SVN, which plugin was faulty. So all of my GUI-Application started, but got freeze then.

Anyway, thank you for your big Help!

Michael Schmidt
  • 9,090
  • 13
  • 56
  • 80