JTextArea artifacts when selecting/deselecting text

I just bumped up against a font rendering issue with JTextArea. I have no doubt that it's a bug, but does anyone know of a workaround?
Run the program below and select/deselect text by double-clicking words. The text is painted in a different location when selected and deselected. Try selecting by dragging the mouse or pressing shift and left/right arrow keys -- same problem, but the actual pixel location of the artifacts sometimes differs depending on the selection start and end, and the way the text was selected (keyboard/mouse drag/double click).
Now try selecting the last word ("dog") by double clicking.import java.awt.Font;
import java.awt.font.TextAttribute;
import java.util.HashMap;
import java.util.Map;
import javax.swing.*;
public class TextAreaProblem {
  public static void main(String[] args) throws Exception {
    SwingUtilities.invokeLater(new Runnable() {
      @Override
      public void run() {
        new TextAreaProblem().makeUI();
  public void makeUI() {
    Map<TextAttribute, Object> attributes = new HashMap<TextAttribute, Object>();
    attributes.put(TextAttribute.FAMILY, "Arial");
    attributes.put(TextAttribute.SIZE, 36.0);
    attributes.put(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE);
    attributes.put(TextAttribute.TRACKING, TextAttribute.TRACKING_LOOSE);
    Font font = Font.getFont(attributes);
    font = font.deriveFont(attributes);
    final JTextArea textArea = new JTextArea("The quick brown fox jumps over the lazy dog.");
    textArea.setFont(font);
    textArea.setLineWrap(true);
    textArea.setWrapStyleWord(true);
    JFrame frame = new JFrame();
    frame.add(new JScrollPane(textArea));
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(850, 200);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
C:\Users\Darryl>java -version
java version "1.6.0_17"
Java(TM) SE Runtime Environment (build 1.6.0_17-b04)
Java HotSpot(TM) Client VM (build 14.3-b01, mixed mode, sharing)Any tips for a workaround will be much appreciated.
Thanks, Darryl

The fix using System.setProperty worked 100% for all font and attribute combinations I tried -- thanks again.
2) Does it work to set the property after the GUI is already created and shown? (shall test that myself in a few hours, but would be nice to know earlier :)No. However, you may set this property as a component client property (on the JTextComponent), but before that component is made visible.This didn't work for me. I tried both putClientProperty and getDocument().putProperty, as suggested in the other thread. What did I miss?import java.awt.Font;
import java.awt.font.TextAttribute;
import java.util.HashMap;
import java.util.Map;
import javax.swing.*;
public class TextAreaProblem {
  public static void main(String[] args) throws Exception {
    //System.setProperty("i18n", Boolean.TRUE.toString());
    SwingUtilities.invokeLater(new Runnable() {
      @Override
      public void run() {
        new TextAreaProblem().makeUI();
  public void makeUI() {
    Map<TextAttribute, Object> attributes = new HashMap<TextAttribute, Object>();
    attributes.put(TextAttribute.FAMILY, "Arial");
    attributes.put(TextAttribute.SIZE, 36.0);
    attributes.put(TextAttribute.TRACKING, TextAttribute.TRACKING_LOOSE);
    attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
    attributes.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON);
    Font font = Font.getFont(attributes);
    font = font.deriveFont(attributes);
    final JTextArea textArea = new JTextArea("The quick brown fox jumps over the lazy dog.");
    textArea.setFont(font);
    textArea.setLineWrap(true);
    textArea.setWrapStyleWord(true);
    // tried either or both -- didn't help
    textArea.getDocument().putProperty("i18n", Boolean.TRUE.toString());
    textArea.putClientProperty("i18n", Boolean.TRUE.toString());
    JFrame frame = new JFrame();
    frame.add(new JScrollPane(textArea));
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(850, 200);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}Darryl
edit Setting this property seems to remove the ability to render underlined and strikethrough attributes. Changed the code above to add these. When "i18n" is set, they are ignored.
edit2 GlyphPainter2 also doesn't appear to support foreground/background colors and swap_colors. It's beginning to look like whoever wrote that class solved a single problem of cumulative integer math error but introduced several others. Or maybe just didn't reimplement the features that weren't inherited..
Edited by: DarrylBurke on Sep 8, 2010 5:13 AM

Similar Messages

  • Why am I getting visual artifacts when typing in text fields?

    Since upgrading to Firefox 4, I get weird graphic artifacts when typing in text fields on websites. I'm getting them right now as I type this! They appear below and to the right of the line of text. The artifacts disappear when the page is refreshed or if the window is resized. This bug only happens in Firefox. My video card drivers are up to date.
    Here is an example: http://i87.photobucket.com/albums/k136/tobe82/ff4bug.jpg

    I've gotten this issue on Windows 7 and on Ubuntu. To fix, go to Options->Advanced->Disable Hardware Acceleration.

  • Possible Bug when selecting the "text" tab on a Line Chart

    Thought I would pass this on.  Not sure if it has been logged yet or not.  Sometimes when building a line chart, the properties field locks up when I try and select the "text" tab.  The dialog boxes in the "text" tab do not show up and the "layout" tab is also highlighted.  I do not know what causes this, but it has happened to me numerous times.  The only solution is to totally delete the line chart and start all over.  It may be related to copying and pasting.  I set up a chart the way I need it and then copy/paste it rather than making all the changes on a default settings chart when I need another chart.
    Stan

    Hi Stan,
    Are you encountering this problem in the RTM version or SP1?
    Can you list the exact steps to reproduce this problem in the most simple case?
    Example:  add line chart, bind to data, copy, paste, click on text tab...............
    Thanks,
    Gerrit

  • Changing the Check Box color when selected/deselected

    How do I do this using the Action tab in Check Box Properties within Acrobat 7.0 (NOT DESIGNER)?
    I added the check boxes to the .PDF using the check box tool (Box Only-No Text).
    I am trying to fill the box green when selected and yellow when not selected via ACTION>Mouse Up>Run a JavaScript>Add and enteringthe javasript below with no success:
    if (this.rawValue == "1") {this.fillColor="0,255,0";} else {this.fillColor="255,255,0";}
    PLEASE HELP!!!

    If you are in AcroForm and not LiveCycle Designer, you not use LiveCycle Designer FormCalc syntax or LiveCycle Designer references.
    With a single check box:
    if(event.target.isBoxChecked(0)) {
       event.target.fillColor  = color.green;
    } else {
    event.target.fillColor = color.yellow;

  • Highlight word in a script when selecting a text

    Hi,
    Is there a setting I can configure so that when I select a word in a script, it will highlight in all occurances in rest of the document? Similar to notepad++ does in green when you select a word?
    Cheers.
    Using 3.2.20.09

    Hi,
    You may have noticed the Edit -> Find... dialog (Ctrl-F in a worksheet or editor) contains the option Highlight All Occurrences. If that option is not grayed out and you can actually check it off, then it will do what you want. Highlighting a word before opening the Find dialog automatically makes it the Text to Search For.
    Unfortunately Highlight All Occurrences seems to be grayed out in all current or older SQL Developer releases I have seen. I believe it is fixed in the next release.
    Regards,
    Gary
    SQL Developer Team

  • When selecting SMS/Text Message iPHone 4 changes it to MMS message!

    I am having a weird problem with my iPhone 4 - when I select "text message" either by starting a text from the "messages" menu or from within "contacts" it sometimes (about 50% of the time) tries to change the message into an MMS. If I don't attach an image it won't allow me to send even though there is only text in the message.
    I can't seem to find a wqay to change it from an MMS to a standard text message so end up cutting the text, switching the phone off and on again and trying to paste the same text into a new message. This only works some of the time .. very curious to know if anyone else has this problem as I LOVE this phone but this particular thing is driving me crazy!! Thanks

    May be that it has become necessary to swap out one application module for another to initiate the SMS Application.
    With all the new features recently added by Apple such as the iTunes Store, Apple may have had to implement an application switching algorithm to keep the maximum memory available for videos, music, ringtones, etc. storage.
    Just one possible reason for a delay - application switchout (paging).

  • Framemaker 7 crashes when selecting/highlighting text

    At pretty random moments my FrameMaker 7 stops working and it seems to do that only when I use my mouse to highlight a portion of text. Now I also noticed it happen when dragging (by mouse pointer) an endpoint of a straight line.
    It never occured under Windows XP and now does very often under Windows 7.
    Anyone had this problem or know a solution?

    GwenchMach,
    Arnis Gubins' (thanks!!) solution, given 3 posts up, solved all my problems. Sorry for not returning here to say that it was the correct answer.
    So, I'm pretty sure you will be helped too if you "run FM7 in XP compatibility".
    I hope you will tell if it was correct for you too.
    Good luck,
    UH

  • CS5 issue - Selecting TLF text sorta freezes flash

    When I use TLF text in CS5 flash seems to use to capacity / I cannot do any clicks for around 10 secs when selecting/deselecting textfield.
    What could be the reason for flash slowing down so extremely?
    Im using WinXP, SP3
    System: HP xw6600 Workstation @ 2.50GHz, 3,25 GB GB of RAM,

    It already happens whenever I place a textfield on stage and set its type to "TLF Text". No matter what action I perform with flash (menu, tool, timeline clicks) everything is really slow and flash freezes for several seconds when there is a TLF textfield instance on stage. Most of the time when clicking something the window title bar of flash changes its look to a window which seems to have crashed (see screenshot).
    Im not sure if this has something to do with it but I have used a Trial version of CS5 before which was updated to a full version of flash.
    My current flash CS5 version is 11.0.2.489.
    I saved a fla with one TLF Text on stage; please find it here:
    http://video.juwimm.net/test/tlf_text.fla
    Please let me know when you grabbed the file so I can delete it.

  • Screen artifacts when using powerpoint / graphics card issue

    Hello,
    since the beginning we are having problems with our powerbook G4 and ibook when using powerpoint.
    We have screen artifacts when selecting and deselecting any object. For a screenshot with explanations please see:
    http://www.flickr.com/photos/18582065@N00/265911667/
    The problem was verified by the Apple store support team, who confirms the issue but cannot help.
    The problem is persistent over all SW versions (Panther and Tiger).
    We would be very happy about any useful idea or solution.
    Thanks,
    Chris
    Powerbook G4   Mac OS X (10.4.8)  

    Update:
    The problem still exists with the Powerpoint/Office version 11.3.0 (released this week).

  • Jtable: set different icons for  selection/deselection

    Hai,
    I have designed a Jtable, I would like to set a column that has to show different icons when selected/deselected that row. To be specific when you click for the first time, it has to show ICON1 and if you click again it has to show ICON2. Any ideas ???
    Thanks,
    Bala.

    I haven't tried this - so take it with a grain of salt. In your table model, you can define the getColumnClass for the column as ImageIcon.class. In the getValue for that column, you would return the icon.
    In order to get the cell to act like a button .. so you can alternate between the icons ... is a little more complex. There is a book on Advanced Swing by Kim Topley that gets into making cells act like buttons. This part works because I have tried it -- but I wasn't displaying icons.
    good luck!

  • CR duplication when Copy/Pasting text from a JTextArea

    I have a typical scenario of having text in a JTextArea. When I select some of that text and try to paste it either to an external text editor or even in the same JTextArea, I am getting extra line spaces in the screen.
    For example, if I have the following text:
    <a id=1>
       <b/>
    </a>When I copy paste it, I get:
    <a id=1>
       <b/>
    </a>When I looked to see what characters were being used for the CR, I see "\r\n". This is the standard line.seperator for Windows OS which is fine. When I save this text to a file using the Java I/O libraries, it is fine (no extra lines). But when copy/pasting it prints extra lines.
    Has anyone had similar problems?

    Has anyone had similar problems? No. How are you doing the copy/paste? Did you write your own routines or are you using the default Actions. By default, when a Document is loaded it will convert the "\r\n" end of line string to "\n" and store the single character in the Document. When you use the getText(..) method the enod of line string will be expanded to "\r\n" on a Windows system, but this should not happen in a copy/paste operation. How do you add data to your text area?
    This section from the Swing tutorial on "Text Component Features" has a working example of using copy/paste:
    http://java.sun.com/docs/books/tutorial/uiswing/components/generaltext.html

  • Text in web pages becomes corrupt, temporarily fixed by selecting & deselecting.

    When reading text part of it becomes blocky & unreadable. If I select the text then deselect it, it becomes ok for a short time but soon becomes corrupt again. Only sections of the text are affected at any one time,but it is very frustrating. It's even happening to the text I'm typing at the moment. I've tried several of the suggestions given but to no avail.

    hello samgill, this sounds like an issue with hardware acceleration - please try [[Upgrade your graphics drivers to use hardware acceleration and WebGL|updating your graphics driver]], or in case this doesn't solve the issue or there is no new version available at the moment, disable hardware acceleration in ''firefox > options > advanced > general''.

  • How to Print Text in the PLD when we select Type : Text

    Hi All
    I designed a PLD for Purchase Order which is working well but
    whenever we select type: Text and we enter some text in the row level for each item. when we see the PLD priview
    Items are displaying but the text below the items are not displaying
    it displays an empty row after each item
    How should i print text in the PLD
    I required in this following Format
    ITEMCODE  DESCRIPTION      QTY
    001              XYZ                      20
    this is capital Good Item
    002             PQR                        30 
    this is Raw Material
    In this above format
    I didnt get the text below the Items
    Can any one suggest the correct answer

    Thanks for your reply
    I already select the linetext field from table POR10 and kept it  in the PLD
    but i didnt get my required format
    after giving that line text field  iam getting
    in this way
    S.No.        ITEMCODE   DESCRIPTION  QTY
       1               001               XYZ                 20
    this is Capital Goods
      2                                                                 
    this is Capital Goods
    the text is repeating twice
    I Put the ItemDescription field  in POR1 and Line Text Field in POR10 in the same repetitve area

  • Flash CS 5.5 Crashes when selecting Text Tool

    Need some help here.  Trying to work on a project for class and everytime I select the text tool (menu bar/tool bar/keyboard shortcut) it crashes...I have tried using both purchased product and trial version.  Getting no help from support when I chat or call in.  If anyone has had this problem can you throw some help me way??

    Well, wonky extension seems like a good idea, but can be withdrawed because I haven't installed one.
    The font issue is also equally probable. As already mentioned: The interesting aspect here is, that both InDesign CS6 and CC will crash. It happened the first time when Windows decided to blue screen and f*** up my account (I wasn't able to log in anymore, I had to made a new one). I once read in another thread that there is a problem occuring when having multiple Windows accounts with InDesign running. Re-installing InDesign didn't help. Font problem after all?
    I have installed at the moment:
    MainType
    NexusFont
    Typograf
    and some small others, like: dp4 Font Viewer or FontViewOk

  • When i select a text layer and invert it (black to white) the whole picture gets inverted

    when i select a text message an invert it, the whole picture gets inverted  - waht am I doing wrong?

    Incidentally, if the text layer is the only visible layer you will need to simplify it before you can invert it.

Maybe you are looking for