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 4 of 4

Thread: JTextPane focus problem

  1. #1
    Junior Member
    Join Date
    Oct 2009
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default JTextPane focus problem

    Hi.. I'm really confused why I can't make my JTextPane focused

    I have a jframe with JTabbedPane inside it, inside the JTabbedPane is a JPanel, inside the JPanel is JTextPane included with JScrollpane.

    I want to make the JTextPane focused when the window opened, now it focused on the JTabbedPane.

    I've tried these

    	TextPane.setFocusable(true);
            TextPane.requestFocusInWindow();
            TextPane.setFocusCycleRoot(true);
            TextPane.setFocusTraversalPolicyProvider(true);
            TextPane.grabFocus();
            TextPane.setCaretPosition(0);
            TextPane.setText("test");

    I even tried to turn off the focusable of JTabbedPane to false.
    Still I can't make the JTextPane focused.
    I also already tried to move the code above before the JFrame.setvisibile(true)

    Anyone can help?


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: JTextPane focus problem

    Try calling requestFocus() on your JTextArea. This should be called after you call pack() on your JFrame.

  3. #3
    Junior Member
    Join Date
    Oct 2009
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: JTextPane focus problem

    Quote Originally Posted by copeg View Post
    Try calling requestFocus() on your JTextArea. This should be called after you call pack() on your JFrame.
    I've tried that too, isn't requestFocusInWindow() is more recommended than requestFocus()? That's what I read at the javadoc

    Note that the use of this method is discouraged because its behavior is platform dependent. Instead we recommend the use of requestFocusInWindow().
    Last edited by LeonLanford; June 21st, 2010 at 11:04 PM.

  4. #4
    Junior Member
    Join Date
    Oct 2009
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: JTextPane focus problem

    ok I found the solution, I must pack the the jframe to make the request focus working..

Similar Threads

  1. Java JTextPane Save
    By ikurtz in forum File I/O & Other I/O Streams
    Replies: 9
    Last Post: April 28th, 2010, 01:02 AM
  2. Need help with setting multiple font styles in jTextPane
    By jch02140 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: January 23rd, 2010, 06:16 AM
  3. switch focus to another window
    By tuansoibk in forum AWT / Java Swing
    Replies: 1
    Last Post: November 13th, 2009, 02:02 PM
  4. Replies: 9
    Last Post: June 27th, 2009, 04:05 PM
  5. Replies: 3
    Last Post: April 20th, 2009, 08:35 AM