Text selection issue
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Text selection issue

  1. #1
    Join Date
    Oct 2011
    Posts
    2

    Text selection issue

    Hi,

    I have a problem with selecting text in a text area. The following video shows 2 windows.

    www.youtube.com/watch?v=JjuEBuEcaLA

    The window on the left is a JTextArea component. As I drag the mouse over the text, the selection is made when the pointer is at the START of the tab. The window on the right shows the same content in NotePad, but as I drag the mouse over this text, the selection is made when the pointer is over the CENTER of the tab.

    How do I get the behavior of NotePad in Java? This may be specific to my computer, I have not tested on other computers. The following code is used to create the test app.

    Code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    public class Test extends JFrame {
    public Test() {
    	addWindowListener(
    		new WindowAdapter() {
    			public void windowClosing( WindowEvent event ) {
    				System.exit( 0 );
    			}
    		}
    	);
    
    	setTitle( "Test" );
    	setLocation( 500, 100 );
    	add( new JTextArea( "\ta\n\tb\n\tc" ) );
    	pack();
    	setVisible( true );
    	setSize( 200, 200 );
    }
    public static void main( String[] args ) {
    	new Test();
    }
    }
    I'm guessing the issue has to do with the Cursor class and how it handles mouse events, but cannot see an easy solution. Thanks in advance for any help...

  2. #2
    Join Date
    May 2006
    Location
    UK
    Posts
    4,474

    Re: Text selection issue

    On my system (Win XP) it does exhibit the behaviour you want ie when you drag past the halfway point of the tab the whole tab becomes selected.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  3. #3
    Join Date
    Oct 2011
    Posts
    2

    Re: Text selection issue

    Hmmm, thanks for testing it out. I'm also using WindowsXP. Could you let me know what "java -version" says? I'm using:

    java version "1.7.0"
    Java(TM) SE Runtime Environment (build 1.7.0-b147)
    Java HotSpot(TM) Client VM (build 21.0-b17, mixed mode, sharing)

    java and javaw seem to give the same result.

  4. #4
    Join Date
    May 2006
    Location
    UK
    Posts
    4,474

    Re: Text selection issue

    java version "1.6.0_23"
    Java(TM) SE Runtime Environment (build 1.6.0_23-b05)
    Java HotSpot(TM) Client VM (build 19.0-b09, mixed mode, sharing)
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center