3 Replies Latest reply on Oct 24, 2008 3:34 PM by camickr

    JTextPane selection color problem

    843806
      I 've createa a simple editor by using jtextpane, but i have a problem about the selection color :

      when i drag the mouse to select some text in the textpane, the selection color is blue (see figure below)

      http://i35.photobucket.com/albums/d186/bobbi2004/1.gif

      and then i change the style, bold for example, but the selection color becomes transparent (although there is still a selection there.)
      http://i35.photobucket.com/albums/d186/bobbi2004/2-1.gif

      i have seen some example about jtextpane but there was no problem, but i can't figure it out why.
      thanks for helping me.

      ps : this is the NetBeans source files for this editor.
      http://www.mediafire.com/?iukjmvj5mwn


      thanks again, and sorry for my bad english

      Edited by: bobbi2004 on Oct 24, 2008 12:21 AM
        • 1. Re: JTextPane selection color problem
          darrylburke
          It's my experience here that members aren't too interested in downloading code posted on some other site (which may be blocked from many offices), and even less interested in looking at ugly, over-complicated IDE generated code. To get better help sooner, post a SSCCE that clearly demonstrates your problem. Not the entire program, just a short-as-possible compilable code that can be indempendently executed.

          Use code tags to post codes -- [code]CODE[/code] will display as
          CODE
          Or click the CODE button and paste your code between the {code} tags that appear.

          db
          • 2. Re: JTextPane selection color problem
            843806
            sorry , but i don't really know where the problem is, so i just post it entirely, about the pictures, i can't post picture in sun forum, so i put them online.
            • 3. Re: JTextPane selection color problem
              camickr
              but the selection color becomes transparent (although there is still a selection there.)
              The selection is only painted when the text pane has focus.

              Make your buttons non-focusable and the focus will remain on the text pane even when you click the button.

              button.setFocusable( false );