Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: mouse listener on jtextarea

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default mouse listener on jtextarea

    hi, i want to detect mouse events on 4 jtextareas.
    this is what i have.
    Color orange=new Color(228,158,96);
    add(Texta);  
    Texta.setFont(font);
    Texta.setForeground(orange);
    Texta.setBounds(88,386,200,40);
    Texta.setEditable(false);
    Texta.setOpaque(false);
     
    add(Textb);  
    Textb.setFont(font);
    Textb.setForeground(orange);
    Textb.setBounds(410,386,200,40);
    Textb.setEditable(false);
    Textb.setOpaque(false);
    Textb.addMouseListener(this);
     
    add(Textc);  
    Textc.setFont(font);
    Textc.setForeground(orange);
    Textc.setBounds(88,465,200,40);
    Textc.setEditable(false);
    Textc.setOpaque(false);
    Textc.addMouseListener(this);
     
    add(Textd);  
    Textd.setFont(font);
    Textd.setForeground(orange);
    Textd.setBounds(410,465,200,40);
    Textd.setEditable(false);
    Textd.setOpaque(false);
    Textd.addMouseListener(this);

    how should i handle events?
    i want to do some things if mouse enter,exit,or click each of the text.
    should i add 4 listeners to the texts or just 1 to the panel?


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,360
    My Mood
    Hungover
    Thanks
    144
    Thanked 626 Times in 537 Posts

    Default Re: mouse listener on jtextarea

    You can either use 4 different listeners, or you can check the source of the event in a single listener.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Mouse Click Action Listener for JTextField?
    By Catlitter68 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 12th, 2013, 10:11 AM
  2. Draughts using mouse listener problem
    By xooch in forum What's Wrong With My Code?
    Replies: 24
    Last Post: April 18th, 2012, 04:39 PM
  3. Adding a mouse listener to my Draughts game
    By MXA92 in forum Object Oriented Programming
    Replies: 10
    Last Post: March 22nd, 2012, 06:43 PM
  4. implement mouse listener class
    By vnsgbt in forum AWT / Java Swing
    Replies: 1
    Last Post: October 24th, 2011, 06:06 PM
  5. [SOLVED] Is it possible for a mouse listener to exist without a GUI interface?
    By techwiz24 in forum Java Theory & Questions
    Replies: 3
    Last Post: August 3rd, 2011, 02:32 PM