JTextArea problem: mouseClicked event irregular

My application allows user to add several CalcArea objects (a subclass of JPanel) in a big JPanel. Highlight of ClassArea class is given below.
Strangely, I find that once in a while, mouseClicked event is not fired. It is very critical for my user to select a particular CalcArea and modify/update the currently selected CalcArea. It is very much annoying to find that the mouseClicked event occurs irregularly. Please advise me how I can make sure mouseClicked event occurs when user clicks on the desired CalcArea. Thanks.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.math.*;
import javax.swing.border.*;
import java.awt.print.*;
public class CalcArea extends JPanel implements MouseListener, FocusListener
   JTextArea ta;
   DrawPanel dp; //subclass of JPanel
   static int iCount=0;
   static int selectedMemberID=-1;
   int memberID;     //unique ID (0-based)
   //constructor
   public CalcArea(String strID....)
   }  //constructor ends
   public void mousePressed(MouseEvent e)
   } //method mousePressed ends
   public void mouseClicked(MouseEvent e)  //***Problem here
     selectedMemberID= memberID;
     System.out.print("mseClicked***");
   public void mouseReleased(MouseEvent e) {}
   public void mouseEntered(MouseEvent e) {}
   public void mouseExited(MouseEvent e) {}

Is there any way to solve it? I don't really understand what you are trying to accomplish, but maybe somthing like the following will help:
e.getComponent().getGraphics();
e.getComponent().getParent().getGraphics();

Similar Messages

  • How to handle mouseclicked events in a ListView node correctly?

    Hi
    We want to simulate table rows and headers with a ListView. We have an additional requirement that when a particular row is selected, a X icon will appear at the last column. Clicking which will remove the row from the table.
    A snippet from the implementation is given below
    public class SampleList extends ListView{
        function getRow(row :Row, index:Integer, cell:ListCell):Node {         
             HBox {
                    var closeView : Image
                    content : [
                    Label {textWrap:true, text: bind row.id, layoutInfo: bind LayoutInfo {width:width * .2, height:height * .02 }}, //some column 1
                    Label {textWrap:true, text: bind row.name, layoutInfo: bind LayoutInfo {width:width * .12, height:height * .02 }}, //some column 2                                               
                    close = ImageView {
                                            image : Image{url:"close.png"}
                                            disable: bind cell.selected and not cell.empty
                                            pickOnBounds : true                                   
                                            onMouseClicked : function (event):Void{
                                              if (not close.disable)
                                            //delete from row from model (Row)
                                            } //close column
         override var cellFactory =  function () {     
                def cell : ListCell = ListCell {       
                onUpdate:  function() {                    
                        def item = cell.item;              
                        cell.node = if (item == null) null; else getRow(cell.item as Row, cell.index,cell);                                          
    }      The problem with the code is that the mouse clicked event used by the close button is multiplexed - Firstly - the application logic - it is used to delete the row from the model and secondly - the ListView control - uses it to trigger a item selection internally. As a result, if you click on a row which is not yet selected (in the sense that it is highlighted) at the exact location of the X icon, the row is deleted without it having been ever highlighted
    If you note the code above, you will notice that the close image's mouseclicked event checks cell.selected before deleting it. And cell.selected is true even though the list has not been highlighted
    Any workarounds for this problem would be appreciated
    Thanks
    Dhruva

    User, please always tell us your jdev version.
    In general you use a valueChangeListener which is fired when the user tabs out of the field...
    Timo

  • MouseClicked event

    I have been having some inconsistencies with mouseEvents not firing. I have a mouseClicked event handler assigned to a radio button within a JTable. Occasionally it does not register clicks of the mouse - which obviously causes all manner of problems. I have traced the problem down and it appears to be that the mouseClicked is affected by moving the mouse between pressing and releasing - even if the mouse doesnt exit the radio button (mouseExited). I have got around this by changing to a mouseReleased but my question is:
    Is this the normal behaviour or is there some sort of bug or perhaps some problem with the way they are being used.
    I have researched further and this seems to happen to not just be tied to my circumstances - if you go to this address and run the MouseEventDemo you will see that if you move the mouse between clicking and releasing no mouseClicked event fires: http://java.sun.com/docs/books/tutorial/uiswing/events/mouselistener.html
    Or am i being stupid?

    Hi georgemc,
    With regards to whether its best to use with a radio button - probably not but that was just one example of where it is being used. The reason in that case i have needed to use a mouse event on the radio button is to be honest because i cant get a radio button correctly set up within my JTable and so i have had to create an extra column with another radio button and then emulate a radio buttongroup by having the negation of the boolean of the selected radio button set as the value of the other by my mouse listener! This mouse listener also caches changes for later saving back to db
    In an ideal world i would have these two columns in a button group or possibly even better have on bit of data being represented as a pair of radio buttons
    What type of listener would you suggest in the hypothetical situation that i had a working set of radio buttons within a JTable?

  • Intercept a mouseclick event with a background running application

    Ciao to everyone.
    My name is Alessandro and "i have a problem"...
    I want to count every click of my mouse with an application running in background.
    How can i intercept any mouseclick event, also those occurring out of the application?
    I work with Windows XP.
    Thanks and excuse me for my bad english.

    As far as we know when a Java swing application loses focus you can not handle the click being generated by the user.
    Have a look at the following source:
    http://java.sun.com/docs/books/tutorial/uiswing/events/mouselistener.html
    We have developed routines for that kind of handling in C+ and set up java JNI in order to retrieve them, but they are low level routines that need to handle interruptions from the main board (not recomended for average users).
    Answer provided by http://www.consultoriajava.com

  • What is wrong with the mouseClicked event?

    there is a weird problem with my program: I constructed a panel with two componets(I constructed a new class for the component that extends TextArea);Both components are registered in a mouseClicked event(when I click the component, the text in the component will display).Eveything seems OK when I click one component first.But when I click other one, the text in the component will display twice,like I click twice. if I go back to first component,the text in the first one will display three times, like I clicked three times and so on.
    Does anybody can give me some hints?
    thanks in advance

    please check the codes related to event:
    public class VectorCellEditor extends MultilineCellEditor implements MouseListener
              public VectorCellEditor()
                   super();
              public void initialize( InitialEvent ev,CellInfo info,Object o)
                   String str="";
                   if(o==null)
                        str ="";
                   else if(o instanceof String)
                        str =(String)o;
                   else if(o instanceof Vector)
                        String dateString =((Data)(((Vector)o).firstElement())).getDateString();
                        String dataString="";
                        for( int i = 0;i<((Vector)o).size();i++)
                             dataString = dataString+((Data)((Vector)o).elementAt(i)).toString()+"\n";
                        str = dateString+"\n"+dataString;
                   super.initialize(ev,info,str);
                   super.setEditable(false);
                   addMouseListener(this);
              public void mousePressed(MouseEvent e){}
              public void mouseReleased(MouseEvent e){}
              public void mouseEntered(MouseEvent e){}
              public void mouseExited(MouseEvent e)
              public void mouseMoved(MouseEvent e){}
              public void mouseClicked(MouseEvent e)
                   String s = this.getText();
                   calendar.area.append(s);
         }

  • Problem with event handling

    Hello all,
    I have a problem with event handling. I have two buttons in my GUI application with the same name.They are instance variables of two different objects of the same class and are put together in the one GUI.And their actionlisteners are registered with the same GUI. How can I differentiate between these two buttons?
    To be more eloborate here is a basic definition of my classes
    class SystemPanel{
             SystemPanel(FTP ftp){ app = ftp};
             FTP app;
             private JButton b = new JButton("ChgDir");
            b.addActionListener(app);
    class FTP extends JFrame implements ActionListener{
               SystemPanel rem = new SystemPanel(this);
               SystemPanel loc = new SystemPanel(this);
               FTP(){
                       add(rem);
                       add(loc);
                       pack();
                       show();
           void actionPerformed(ActionEvent evt){
            /*HOW WILL I BE ABLE TO KNOW WHICH BUTTON WAS PRESSED AS THEY
               BOTH HAVE SAME ID AND getSouce() ?
               In this case..it if was from rem or loc ?
    }  It would be really helpful if anyone could help me in this regard..
    Thanks
    Hari Vigensh

    Hi levi,
    Thankx..
    I solved the problem ..using same concept but in a different way..
    One thing i wanted to make clear is that the two buttons are in the SAME CLASS and i am forming 2 different objects of the SAME class and then putting them in a GUI.THERE IS NO b and C. there is just two instances of b which belong to the SAME CLASS..
    So the code
    private JButton b = new JButton("ChgDir");
    b.setActionCommand ("1");
    wont work as both the instances would have the label "ChgDir" and have setActionCommand set to 1!!!!
    Actually I have an array of buttons..So I solved the prob by writting a function caled setActionCmdRemote that would just set the action commands of one object of the class differently ..here is the code
    public void setActionCommandsRemote()
         for(int i = 0 ; i <cmdButtons.length ; i++)
         cmdButtons.setActionCommand((cmdButtons[i].getText())+"Rem");
    This just adds "rem" to the existing Actioncommand and i check it as folows in my actionperformed method
         if(button.getActionCommand().equals("DeleteRem") )          
                        deleteFileRemote();
          else if(button.getActionCommand().equals("Delete") )
                     deleteFileLocal();Anyway thanx a milion for your help..this was my first posting and I was glad to get a prompt reply!!!

  • How do I assign a mouseclick event Listener to a simplebutton already nested in a movie clip when it's dropped on stage?

    I'm trying to assign a mouseclick event listener to a simplebutton nested within a movie clip's later frames, starting at frame 2 and up. This card, however, is not added to my game until later, and when the player clicks on it/turns it over.
    There are four files involved in this program:
    #1 The main actionscript file, which corresponds to
    #2 my dreamQuester .fla file.
    #3 my artifactCard file movieClip's corresponding .as file,
    #4 my combo1.as file corresponding to a an instance of a simpleButton named combo1 that is already
    nested --and this instance is already named-- inside/as a child of said artifactCard movieclip.
    What I've done so far isn't working:
    In my main dreamQuester.as file, when a player clicks on an artifactCard, its MOUSE_DOWN event
    listener takes them to this function (clickArtCard), where the trouble is at:
    // player clicked on the artC card--which is a child of posArt1 on stage--to turn card over:
            function clickArtCard(a_event:MouseEvent) {
                var thisArtCard:artifactCard = (a_event.target as artifactCard);
                thisArtCard.gotoAndStop(unclickedArt1);  // go to frame number of artifact
                                    // card where combo1 button is.
                thisArtCard.removeEventListener(MouseEvent.CLICK,clickArtCard);
                thisArtCard.buttonMode = false;
                trace("combo1.combo is:" + combo1.combo);
                trace("posArt1.artC.combo1 is:" + posArt1.artC.combo1);
                posArt1.artC.combo1.addEventListener(MouseEvent.MOUSE_DOWN, comboClickedWHO);
    when the artC card--the static public instance of artifactCard--is clicked, it only gets to the
    trace("posArt1.artC.combo1 is:" + posArt1.artC.combo1); which returns this error message:  
    TypeError: Error #1010: A term is undefined and has no properties.
        at MethodInfo-61()
    So do how would I declare a static public variable of this simpleButton at the start of my main .as
    file to make it defined to get a mouseDown actionListener into my pre-existing-and-named-instance
    combo1 simpleButton?
    perhaps there is a way, while the debug movie program is running, to click on the simpleButton and see exactly
    what it's parent heirarchy is, to see the name of all parents above the simpleButton incase they are
    different then what I think?
    (just in case, I was hoping to squeeze a zip file containing these files to be less than 9MB incase someone was willing to look at my files to see what I've done so far, but 9 megs is just too big! even though all graphics I've imported where turned into vector graphics with trace bitmap. I wish there was a way to check the file size of each symbol in Flash CS4, here...)
    Thank you so much for any help!
    ~Ethan

    Just use a
    stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
    function keyPressed(event:KeyboardEvent):void {
         //trace(event.keyCode);
         if(event.keyCode == ???){
              // play the sound
    Where I show the "???" you would replace with the keyCode for the key you want pressed for that sound.  To determine the keyCode you can use the trace line that I have commented out.
    Note that when testing in Flash you often need to disable the keyboard shortcuts in the Flash Player in order to be able to use alot of the keys.  You will find this option in the Control menu options in the player.

  • MouseClicked event = enter key doesnt work

    Hello,
    when I make some JButoon and add to it MouseClicked event (witch handles some code) everything works fine. But when I mark it with TAB then press ENTER button wont "doClick".
    So I found out that actionPerformed might be the right handler, but I dont understand why there is also mouseClicked event?
    Is actionPerformed event what I need (to work either with LMB or ENTER key) ?
    Are there any disatvantages of actionPerformed event comparing to mouseClicked event?

    The spacebar, not the Enter key, is the default keyboard trigger for a button that has the focus (and not just in Java).
    If you really want the focused button to respond to the Enter key, search this forum for"DefaultButtonFollowsFocus".
    db

  • Problems using event structure to write new parameter values to VISA

    Attachments:
    FMA_event_2.vi ‏28 KB
    FMA_event_2.vi ‏28 KB

    It seems I'm also having trouble using forums..not sure what happened...updated and corrected thread: http://forums.ni.com/t5/LabVIEW/Problems-using-event-structure-to-write-new-parameter-values-to/td-p...

  • Problems with events in flex

    Hi there. I'm a AS2 and Flash CS3 guy. I started to learn AS3 and transfer to Flex 3. But I got a problem w/ Events in AS3. I'm adding a canvas component to the stage. On that canvas, I added 3 different events: mouse down, mouse move, and mouse up. When mouse move is fired, there is no way for me to get mouse up event fired, and viceversa, when mouse up is fired, there is no way to get the mouse move event fired. Is there any one to help this newbie with this particular problem? Any help will be very appreciated.
    Code:
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
    <mx:canvas id="myCanvas" x="50" y="50" width="500" height="500" click="event_1();" mouseMove="event_2();" mouseUp="event_3();">
    </mx:Canvas>
    <mx:Script>
    <![CDATA[
    import mx.controls.Alert;
    import flash.events.*;
    public function event_1():void
    { Alert.show("First event fired"); }
    public function event_2():void
    { Alert.show("Second event fired"); }
    public function event_3():void
    { Alert.show("third event fired); }
    </mx:Script>
    </mx:Application>

    Hi Greg. Thank you for your replay. The question is I didnt want to bother you with the complete code and post it with the minimal expression. But here I give you the full code w/corresponding package. What I'm trying to do is drawing a line over an empty canvas (I got it very easily in Flash AS2)
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="addChild(p1)">
    <mx:Canvas id="wrapper" x="10" y="10" width="600" height="600">
      <mx:Canvas x="50" y="50" width="500" height="500" id="imageView" backgroundColor="#F8F3F3" click="startDraw();" mouseMove="drawLine();" mouseUp="noDrawLine();" >
      </mx:Canvas>
    </mx:Canvas>
    <mx:Button x="263" y="618" label="Draw Line" click="prepToDraw();"/>
    <mx:Script>
    <![CDATA[
      import com.myDomain.Lines.Main;
       import mx.graphics.*;
       import mx.binding.utils.BindingUtils;
       import flash.events.IOErrorEvent;
       import flash.events.Event;
       import flash.display.*;
       import mx.controls.Alert;
       import com.myDomain.Lines.Main;
       public var p1:Main = new Main();
       public var pre:Number = 0;
       public function prepToDraw():void
        pre = 1;
       public function startDraw():void
        if(pre == 1)
        p1.graphics.clear();
        var newColor:int = 0xFF00FF;
        var iniX:Number = mouseX;
        var iniY:Number = mouseY;
        var lineWidth:Number = 10;
        p1.graphics.lineStyle(lineWidth, newColor);
        p1.graphics.moveTo(iniX, iniY);
       public function drawLine():void
        if(pre == 1)
         p1.graphics.lineTo(mouseX, mouseY);
       public function noDrawLine():void
        if(pre == 1)
         Alert.show("noLine");
    ]]>
    </mx:Script>
    </mx:Application>
    The package:
    package com.myDomain.Lines
    import flash.display.Shape;
    import flash.display.Stage;
    import flash.events.MouseEvent;
    import mx.core.UIComponent;
    public class Main extends UIComponent
      public function Main()
       super();
      public var p1:Shape = new Shape();
    If you go apply the code, you will see: 1) The first event to fire is mouseUp, then you eill start drawing the line, but again, you will not be able to stop this event with mouseUp. If you can help me, I will be very appreciated. Thanks. 

  • Problem receiving event invitation-not on "me" card

    I have been trying to delete past event notifications/invitation, but when I select them, I get the error message "Problem receiving event invitation - not on "me" card. Someone invited you to an event using an email address that isn’t on your “me” card in Address Book. Find your email address in the following list and add it to your card in Address Book."
    What does this mean? The message does not show a 'following list'. I checked my Address Book "me" card, and it contains all my e-mail addresses.
    thanks!

    I get these all the time, and have yet to figure out how to get them to add to my calendar.
    I'm trying to figure out how to "open" it so I can see what the address conflict is. There appears to be no way to view the actual event, so I can see what address the event thinks is "missing.
    I will keep trying to resolve this (what I call a bug) problem, and will reply here if I come up with something.
    Steve

  • InputVerifier for JTextArea problem

    Hello,
    I am having a problem with using an InputVerifier to check a max character limit on a JTextArea. It seems that occasionally after the verify of the JTextArea fails, I lose the next character I type into it! Here is the code, followed by a description of how to reproduce the problem. Note this code is copied from the Java 1.4.2 API documentation of the InputVerifier class, with the first JTextField changed to a JTextArea and the verify method modified:
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import java.awt.Frame;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.awt.event.WindowListener;
    import javax.swing.InputVerifier;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JTextArea;
    import javax.swing.JTextField;
    public class TestJTextArea  extends JFrame {
        public TestJTextArea () {
           JTextArea ta = new JTextArea ("");
           ta.setPreferredSize(new Dimension(100, 50));
           getContentPane().add (ta, BorderLayout.NORTH);
           ta.setInputVerifier(new PassVerifier());
           JTextField tf2 = new JTextField ("TextField2");
           getContentPane().add (tf2, BorderLayout.SOUTH);
           WindowListener l = new WindowAdapter() {
               public void windowClosing(WindowEvent e) {
                   System.exit(0);
           addWindowListener(l);
        class PassVerifier extends InputVerifier {
            public boolean verify(JComponent input) {
                JTextArea jText = (JTextArea)input;
                boolean retValue = jText.getText().length() < 5;
                if (!retValue) {
                    System.out.println("MAX CHARS");
                return retValue;
        public static void main(String[] args) {
            Frame f = new TestJTextArea ();
           f.pack();
           f.setVisible(true);
    }A way to reproduce the problem is type in the TextArea: "123455", then Ctrl+Tab and the verify will fail. Then backspace twice to delete the "55" and Ctrl+Tab to move to the TextField. Then Tab again to go back to the TextArea and type any charachter over than 5. About 80% of the time, the character that you type will be lost and not appear in the TextArea. It doesn't always happen, but if you try it a few times it will come up. Also, occasionally the backspace keystroke is also lost in the TextArea. Note this only happens when I use Tab. I am not able to reproduce it by using the mouse to change focus.
    I have searched for a bug report on this, but have found nothing. Am I doing something wrong? I am simply using the sample code from the InputVerifier JavaDoc, but with a JTextArea... This is on a WinXP Pro machine with Java Std. Ed. 1.4.2.
    Thank you for your help.
    Angel

    JTextField jtf = (JTextField)comboBox.getEditor().getEditorComponent();
    jtf.setInputVerifier(new YourInputVerifier());

  • MouseClick event on a JLabel inside a TableCell

    I'm building a table and each row contains 5 cells:
    3 uneditable text labels
    edit icon
    del icon
    I want to open a dialog to edit the whole row when I click on the edit icon and delete the row when I click on the del icon.
    But the problem is that when I define a listener inside the cell it seems like the event is never raised or blocked by the JTable.
    I've also tried setting a custom cell editor, but have some other problems releted to the fact that I don't change the cell contents, but all the row content.
    Does anybody have an idea on how to reach this goal?
    Thank you
    Simone

    2 last columns have to be uneditable.
    Add MouseListener to JTable only
    public void mouseClicked(MousEvent e){
      switch(yourTable.columnAtPoint(e.getPoint())){
        case 3://edit
          // --- do edit ---
          break;
        case 4://delete
          // --- do delete ---
          break;

  • Extract text of JTextArea in WindowClosing event()...

    I downloaded the Framework.Java sample code, which creates a new instance of a window. I want to be able to retrieve the text from the JTextArea of a JFrame when the user closes the window.
    I am using this code:
            frame.addWindowListener
           (new WindowAdapter() {
             public void windowClosing(WindowEvent e)
                System.out.println("pane.getText()=" + frame.pane.getText());
              System.exit(0);
            });Unfortunately, I am getting this error:
        "Error: variable pane not found in class.javax.swing.JFrame"How do I get at this text? How do I get the content pane in general? Full source code below:
    import  java.net.*;
    import  javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Framework extends WindowAdapter {
        public int numWindows = 0;
        private Point lastLocation = null;
        private int maxX = 500;
        private int maxY = 500;
        public Framework() {
            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            maxX = screenSize.width - 50;
            maxY = screenSize.height - 50;
            makeNewWindow();
        public void makeNewWindow() {
            final JFrame frame = new MyFrame(this);  //*
            numWindows++;
            System.out.println("Number of windows: " + numWindows);
            if (lastLocation != null) {
                //Move the window over and down 40 pixels.
                lastLocation.translate(40, 40);
                if ((lastLocation.x > maxX) || (lastLocation.y > maxY)) {
                    lastLocation.setLocation(0, 0);
                frame.setLocation(lastLocation);
            } else {
                lastLocation = frame.getLocation();
            System.out.println("Frame location: " + lastLocation);
            frame.setVisible(true);
            frame.addWindowListener
           (new WindowAdapter() {
             public void windowClosing(WindowEvent e)
              System.out.println("pane.getText()=" + frame.Container.getContentPane.getText());
              System.exit(0);
        public static void main(String[] args) {
            Framework framework = new Framework();
    class MyFrame extends JFrame {
        protected Dimension defaultSize = new Dimension(200, 200);
        protected Framework framework = null;
        private Color color = Color.yellow;
        private Container c;
        public MyFrame(Framework controller) {
            super("New Frame");
            framework = controller;
            setDefaultCloseOperation(DISPOSE_ON_CLOSE);
            setSize(defaultSize);
            //Create a text area.
            JTextArea textArea = new JTextArea(
                    "This is an editable JTextArea " +
                    "that has been initialized with the setText method. " +
                    "A text area is a \"plain\" text component, " +
                    "which means that although it can display text " +
                    "in any font, all of the text is in the same font."
            textArea.setFont(new Font("Serif", Font.ITALIC, 16));
            textArea.setLineWrap(true);
            textArea.setWrapStyleWord(true);
            textArea.setBackground ( Color.yellow );
            JScrollPane areaScrollPane = new JScrollPane(textArea);
            //Create the status area.
            JPanel statusPane = new JPanel(new GridLayout(1, 1));
            ImageIcon icoOpen = null;
            URL url = null;
            try
                icoOpen = new ImageIcon("post_it0a.gif"); //("doc04d.gif");
            catch(Exception ex)
                ex.printStackTrace();
                System.exit(1);
            setIconImage(icoOpen.getImage());
            c = getContentPane();
            c.setBackground ( Color.yellow );
            c.add ( areaScrollPane, BorderLayout.CENTER )  ;
            c.add ( statusPane, BorderLayout.SOUTH );
            c.repaint ();
    }

    Hi,
    you get the error-message because pane is not declared in your program anywhere. The JTextArea holds the text - it is declared in the constructor of class MyFrame. The variable textarea holds the reference to this JTextArea - the JTextArea is put in a JScrollPane and the JScrollPane added to the ContentPane of the Frame. After that all is done - at the end of the constructor of class MyFrame - the variable textarea is no longer accessible, because it is declared in the constructor itself and is local to the constructor - which means, it "lives" as long as the constructor is executed.
    One way to let the variable textarea live longer is to declare it outside the constructor - for example in the body of the class where the Container c is declared.Add simply "JTextArea textarea;" there. In the constructor you only use then
    textarea = new JTextArea(....) instead of JTextArea textarea = new JTextArea(...)
    Now the textarea-variable will "live" as long as the instance of the MyFrame-class will be there. If you would be able to access the instance of the MyFrame-class from the windowClosing-method, you would be able to access the textarea too - but you can't in the moment.
    This instance of the MyFrame-class ist constructed in the makeNewWindow-method - here is the same problem as above with the textarea-variable. The variable frame holds the reference to the newly created frame but it is declared inside the method and will not be accessible, when the method has come to an end. So you should declare it outside in the body of class Framework - for example in the place where maxY is declare. Add simply "JFrame frame;" behind the declaration of maxY.
    In the makeNewWindow-method you use
    frame = new MyFrame(this) instead of final JFrame frame = new MyFrame(this)
    Now we are near the solution - the JTextArea is now accessible by frame.textarea - to get the text in the windowClosing-method you now can use frame.textarea.getText().
    There are some other syntax-errors in your text too - your compiler will show them.
    Hope this will help you - I have tried, to explain why it should be done this way - I don't want to post only a few lines of code - sorry, when it is now much to read.
    greetings Marsian

  • JComboBox AutoCompleteDecorator & MouseClicked event

    Hi, I have a problem with a JComboBox's MouseClicked.
    I have imported an AutoCompleteDecorator to my combobox but, because of this, whenever I double click on the combo, it doesn't fire an event.
    To get it to fire an event, I have to click exactly on the combobox's border,which is qiute a hastle. Is there a work around for this or another way to implement autocomplete?

    I've also created a different class that does the same thing, AND still gives me the same problem.
    package oma;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.text.*;
    * @author Zweli
    public class AutoComplete extends JComboBox implements JComboBox.KeySelectionManager{
        private String searchFor;
         private long lap;
         public class CBDocument extends PlainDocument {
                public void insertString(int offset, String str, AttributeSet a) throws BadLocationException {
                    if (str==null) return;
              super.insertString(offset, str, a);
                        if(!isPopupVisible() && str.length() != 0) fireActionEvent();
        public AutoComplete(Object[] items) {
            super(items);
         lap = new java.util.Date().getTime();
         setKeySelectionManager(this);
         JTextField tf;
         if(getEditor() != null) {
                tf = (JTextField)getEditor().getEditorComponent();
                if(tf != null) {
                    tf.setDocument(new CBDocument());
                    addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            JTextField tf = (JTextField)getEditor().getEditorComponent();
                            String text = tf.getText();
                            ComboBoxModel aModel = getModel();
                            String current;
                            for (int i = 0; i < aModel.getSize(); i++) {
                                current = aModel.getElementAt(i).toString();
                                if(current.toLowerCase().startsWith(text.toLowerCase())) {
                                    tf.setText(current);
                                    tf.setSelectionStart(text.length());
                        tf.setSelectionEnd(current.length());
                        break;
        public int selectionForKey(char aKey, ComboBoxModel aModel) {
         long now = new java.util.Date().getTime();
            if (searchFor!=null && aKey==KeyEvent.VK_BACK_SPACE &&     searchFor.length()>0) {
                searchFor = searchFor.substring(0, searchFor.length() -1);
            } else {
                //     System.out.println(lap);
                // Kam nie hier vorbei.
                if(lap + 1000 < now)
                    searchFor = "" + aKey;
                else
                    searchFor = searchFor + aKey;
         lap = now;
         String current;
         for(int i = 0; i < aModel.getSize(); i++) {
                current = aModel.getElementAt(i).toString().toLowerCase();
                if (current.toLowerCase().startsWith(searchFor.toLowerCase())) return i;
            return -1;
        public void fireActionEvent() {
            super.fireActionEvent();
    }Thanx, Zweli

Maybe you are looking for

  • Macbook Pro + M-Audio Studiophile Speakers. VERT quiet sound output!

    Hi All, Kind of a newb here - so I'm not sure if I'm going about this in the right way or not. Here's what's going on: I have an M-Audio BX5a speaker plugged into my Macbook Pro via the headphone jack (1/8" -> 1/4" cable) and even with the sound maxe

  • IMac 27 on the USB cable and electric current passing over me.

    Guys, I have touched on my iMac 27 on the USB cable and I have got an electric current passing over me. My feet were naked. When I got my shoes back the problem gone. Is this normal? Is it safe for my iMac and external devices?

  • Having a problem!

    The horizontal type tool won't type text. The cursor moves in the box created to put text in but no text happens. It's been all right up till now. I have Photoshop CS5 Extended. Can you help?

  • Complete and utter newbie

    I'll try my best to not cop an attitude but this is my first i anything and already I'm frustrated. My wife got me an ipod Nano for my birthday, which generation is anybodies guess. Just purchased it at Best Buy with all the required equipment, to in

  • Newblue Noise Reducer Offline in Premiere Elements 12

    I've been using the Newblue Noise Reducer in Premiere Elements 12, but it's all the sudden gone offline. Does anyone know how I get it back? When I open a new project, the effect won't even show up under audio effects anymore, and when I open a proje