TextLayout swallows Tab Spacings.

Hi,
I'm having trouble rendering tab spacings using Java2D.
The tab spacings seems to be swallowed/ignored.
Here's a simple test application. Am I doing something wrong or missing something? Or is this a bug?
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.font.TextLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class TextLayoutTabSpacingTest extends JPanel
  @Override
  public void paint(Graphics g)
    float X = 40;
    float Y = 80;
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    Font oFont = new Font("Serif", Font.PLAIN, 32);
    TextLayout oTextLayout = null;
    String sOriginalText = "Tab spacings where art thou?\n1\t2\t3\t4\t5\n6\t7\t8\t9\t10\n11\t12\t13\t14\t15";
    String[] aText = sOriginalText.split("\n");
    for(String sText : aText)
      System.out.println("\nText       -> " + sText);
      oTextLayout = new TextLayout(sText, oFont, g2.getFontRenderContext());
      System.out.println("TextLayout -> " + oTextLayout);
      oTextLayout.draw(g2, X, Y);
      Y += 40;
  public static void main(String[] args)
    JFrame f = new JFrame("TextLayout Tab Spacing Test.");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(new TextLayoutTabSpacingTest());
    f.setSize(500, 300);
    f.setVisible(true);
}Thank you.

Looks like you didn't understand Stas' advice.
... and then paint the pane.You already have a JEditorPane with all formatting, so half of that advice has become redundant. Just invoke the JEditorPane's paintComponent(...) with the graphics reference you are using for what you call 'the whole screen' possibly after translating or otherwise applying a suitable transform.
db
edit Saw #5 and 6 after posting that.
@Stas: Did I interpret your previous response correctly?
Edited by: DarrylBurke

Similar Messages

  • Here's a layout puzzle looking for a good solution

    Does anyone have ideas what the best way to do this might be?
    I am writing a long book text (several hundred pages) which should be in a single continuous column. I want to have occasional brief notes placed outside the text and alongside, in the margin, as it were. I also want the margin notes to be tied to specific points in the text. (I.e. if I edit the main text body, so that the text shifts up or down, I naturally want the margin notes to move along with the text they are going with.)
    I've thought of various possible ways of doing this, but none of them seems very elegant, and Pages is nothing if not elegant and simple, so I'm sure there must be a way....
    (1) one way theoretically is to set up the page with two columns, making one of them for the main text and occupying most of the width of the page, say 5", then have a narrow column alongside, say 2", to hold the side-notes (which presumably could be done by lots of small textboxes. But I can't see how to stop Pages from treating the two columns as both being receptacles for the main text and flowing the text from the 5" column into the adjacent 2" column. Am I missing something? (Probably!)
    (2) So maybe I should have have just one column, 5" for the main text. Then can I still put text-holders occasionally alongside it (i.e. for the side-notes)?
    (3) If Yes to (2), is there a way to anchor the text-holders with the side-notes to specific points in the main text? so that if/when I rewrite the main text, and add or subtract parts of it, the text-holders with the side-notes will move appropriately and stay adjacent to the part of the main text they are supposed to be keyed to?
    (4) Or maybe tables is the way to go? I can't see putting the main text (several hundred pages) into tables, but perhaps have a single column for the text (5" or so), and then a table alongside, with lots of cells, most of which will stay blank (and invisible), but some of which will hold the 'margin notes'? Then the anchor question arises again: is there a way to tie in a specific cell so it is always adjacent to a particular part of the main text?
    OK - there's the layout puzzle. What's the tidiest solution? I'm sure I'm missing lots of things...
    Anthony

    I would agree that the two columns are going to be nothing but tricky.
    but of course, there is a different way.
    I assume you want to have a wider than normal margin for your document? Something which wil be able to handle the different text boxes that will be set up?
    Okay. I tried this with one document rather quickly, so here it goes. First of all, start with a normal blank document. In this document set your margins so there is space for your extra margin information. (you do this in the page setup box. Don't use the whole sheet, though, since not all printers go edge to edge)
    Now, using the text inspector go to tabs. We will be wanting to have two different things here. A body paragraph style which goes to the left edge of the margin, and one which starts where the edge of the info box will be. Say 4 cm in.
    The idea is that for those spots where you have the text box, the line starts at the very edge of the margin. This is so you have enough space for the box, which will be set to flow with the text. For those paragraphs where you do not have an info box the margin is set using the indent tab spacings.
    Aw heck, I can't even figure out what I'm saying. You will find a document here: pagesuser.com/images/Infobox_testdocument.zip Clicking the link will possibly download it, could very well uncompress it and quite likely open the Pages document within, or soemthing.
    I know it probably isn't exactly what you need, but it may point you in the right direction.
    Gerry

  • Split command for theTAB spacing in file.

    Hi all,
    Requirement is to read a file from the application server and process it.
    The file has the TAB spacings and seen from AL11 shows # for tabs.
    I have read the line in a character of 1024. Now on splitting at delimiter '/h/' as seen in debug it does not split the line as reqired.
    How to split the columns with tab space.
    appreciate your inputs.
    Thanks,
    Stock

    Hi stock,
    sorry but you can use
    CONSTANTS: CON_NEWL TYPE X VALUE '0D', "OK for non Unicode
                          CON_TAB  TYPE X VALUE '09'. "OK for non Unicode
    or
    CONSTANTS: CON_NEWL TYPE X VALUE %_NEWLINE,
                          CON_TAB  TYPE X VALUE %_HORIZONTAL_TAB.
    Regards, Dieter

  • Tab in TLF !!!

    Hi
    I am trying to implement a sample of TLF with feature of Tab for paragraph like word document. If user click in paragraph and press 'Tab' then it should work like same as we experience in Word.
    Can any one guide me ?
    Bharat Patel

    By default TLF ignores the Tab key and it's used to navigate focus.  This can be changed by creating a custom Configuration and passing it into the TextConverter or the TextFlow constructor.  See the flashx.textLayout.elements.Configuration class.  Note that once a TextFlow is constructed its Configuration cannot be changed.
    There is a defaultConfiguration that is used when no Configuration is specified.  So the simplest way to have all your TextFlows insert a tab on the tab key is to add this line to the startup before any TextFlows are created.
    TextFlow.defaultConfiguration.manageTabKey = true;
    Note that if you are using TLF wrapped by Flex or FlashCS5 then you'll have to work through the components and APIs they provide.
    Hope that helps,
    Richard

  • Extending the Tab Navigator

    Hi,
    I am trying to do some work in Xcelsius that is dependent on knowing which tab is selected in a tab set.  It does not appear that getting this information is possible with the Tab Set component provided by Xcelsius.  I have started to dig into the SDK to see if I can build a Tab Set that behaves identical to the Xcelsius one with the addition of being able to identify which tab is currently selected.
    So far I have been able to get the tab set created with minimal functionality but when testing it I notice that my component will not "swallow up" other components placed on top of it.  Am trying to figure out how to do that (is there a property that needs to be set somewhere?).
    Thanks,
    Mike

    Hi Mike,
    Creating containers is not supported in the SDK, it is on the list of possible futures though...
    Regards
    Matt

  • No Tab key?

    In the following, pressing the Tab key does absolutely nothing. What happend to it? How can I get at it? (I'm writing a code editor - gotta have the Tab key.)
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    import javax.swing.JFrame;
    public class KeyTest extends JFrame implements KeyListener{
         public static void main( String[] args ) {
             KeyTest me = new KeyTest( "key test" );
             me.setBounds( 100, 100, 300, 200 );
             me.addKeyListener( me );
             me.setVisible( true );
         KeyTest( String s ) { super( s ); }
         public void keyPressed( KeyEvent e ) {
             System.out.println( e );
         public void keyReleased( KeyEvent e ) {
             System.out.println( e );
         public void keyTyped( KeyEvent e ) {
             System.out.println( e );
    }

    Duh.
    Add this line to keep tabs from getting swallowed:
             me.setFocusTraversalKeysEnabled( false );

  • Word wrapping: Tab behavior in TLF editor

    Hi,
    I have created an editor using TLF which has word-wrapping enabled. The editor also takes in the Tab key and places it at prober position. In case you insert Tab at the beginning of the line except for the first line then the TAB is inserted in the previous line and it does not get wrapped.
    Is there any way in which I can acheive word wrapping for Tabs? I have observed similar behavior for SPACE as well.
    Why is such a behavior in the both the cases?

    We are using the TLF bundled with Flex 4.1.0.16076, latest production release.   You can verify the problem here in this demo:
    http://labs.adobe.com/technologies/textlayout/demos/
    Type two lines, make sure they wrap.  At the beginning of the second line press the tab key multiple times.  The tabs will stack up on the end of the first line.
    If this is fixed in a newer version of TLF, is it safe to use with flex 4.1?
    Thanks,
    Ryan

  • New to LineBreakMeasurer with tabs

    Hi � can someone please check this code which is from the API. I�m trying to use it pretty much as it comes, without knowing enough to understand all of it. I added some curly braces to a couple of �if� passages (did I want to?). I�ve also added�
         attString = �this is the text I want to display preferably with \t a few \t tabs here \t and there \t in which case I�ll set tabCount to 4 � is that the idea?�;
         Graphics2D g2;
    g2 = (Graphics2D) g;
         g2.setColor(Color.black);
         att = new AttributedString(attString);
         styledText = att.getIterator();
         int tabCount = 4;
    �after the first line. It compiles OK, but it displays blank, unless I set tabCount to zero and (as long as I do) remove the �\t� bits, in which case I get displayed precisely this:
    this is the text I want to display preferably with a few
    this is the text I want to display preferably with a few tab
    this is the text I want to display preferably with a few tabs
    this is the text I want to display preferably with a few tabs
    this is the text I want to display preferably with a few tabs
    here and there in which case I�ll set tabCount to 4 � is
    here and there in which case I�ll set tabCount to 4 � is t
    here and there in which case I�ll set tabCount to 4 � is th
    here and there in which case I�ll set tabCount to 4 � is tha
    here and there in which case I�ll set tabCount to 4 � is that
    here and there in which case I�ll set tabCount to 4 � is that
    here and there in which case I�ll set tabCount to 4 � is that
    the idea?
    the idea?
    Which feels like alot better than nothing! Can anyone tell from this what I need to do? Incidentally, if I put an actual tab space character into the attString text I get displayed just all the text up to the first such tab space. The code from the API is:
    public void paint(Graphics graphics) {
    float leftMargin = 10,
    rightMargin = 310;
    float[] tabStops = { 100, 250 };
    int[] tabLocations = new int[tabCount+1];
    int i = 0;
    for (char c = styledText.first(); c != styledText.DONE; c = styledText.next()) {
    if (c == '\t') {
    tabLocations[i++] = styledText.getIndex();
    tabLocations[tabCount] = styledText.getEndIndex() - 1;
    LineBreakMeasurer measurer = new LineBreakMeasurer(styledText);
    int currentTab = 0;
    float verticalPos = 20;
    while (measurer.getPosition() < styledText.getEndIndex()) {
    boolean lineContainsText = false;
    boolean lineComplete = false;
    float maxAscent = 0, maxDescent = 0;
    float horizontalPos = leftMargin;
    Vector layouts = new Vector(1);
    Vector penPositions = new Vector(1);
    while (!lineComplete) {
    float wrappingWidth = rightMargin - horizontalPos;
    TextLayout layout = measurer.nextLayout(wrappingWidth,
    tabLocations[currentTab]+1, lineContainsText);
    if lineContainsText is true if (layout != null) {
    layouts.addElement(layout);
    penPositions.addElement(new Float(horizontalPos));
    horizontalPos += layout.getAdvance();
    maxAscent = Math.max(maxAscent, layout.getAscent()); maxDescent = Math.max(maxDescent,
    layout.getDescent()+layout.getLeading());
    } else {
    lineComplete = true;
    lineContainsText = true;
    if (measurer.getPosition() == tabLocations[currentTab]+1) {
    currentTab++;
    if (measurer.getPosition() == styledText.getEndIndex()) lineComplete =
    true; else if (horizontalPos >= tabStops[tabStops.length-1]) lineComplete = true;
    if (!lineComplete) {
    int j;
    for (j=0; horizontalPos >= tabStops[j]; j++) {}
    horizontalPos = tabStops[j];
    verticalPos += maxAscent;
    Enumeration layoutEnum = layouts.elements();
    Enumeration positionEnum = penPositions.elements();
    while (layoutEnum.hasMoreElements()) {
    TextLayout nextLayout = (TextLayout) layoutEnum.nextElement();
    Float nextPosition = (Float) positionEnum.nextElement();
    nextLayout.draw(graphics, nextPosition.floatValue(), verticalPos);
    verticalPos += maxDescent;
    }

    mac nincompoop wrote:
    New to Mac. Can't find iWeb on the new iMac. Any solutions?
    iLife 11 ships with new Macs includes iPhoto, iMovie & GarageBand. If you want or need iWeb you can still get it however you need to purchase the box set of iLife11. The box set includes iPhoto, iMovie, GarageBand, iWeb & iDVD. I see this is still available from Amazon for as low as 29.99. To be honest though if you have an older license of iLife you can install only iWeb.

  • Tab control event Keypress

    Hello,
    I'm using a Tab control and can't find out how to handle the following situation.
    We know that when operating a Tab control we can jump from Tab to Tab by pressing <Ctrl-Tab>.
    When at the last Tab I would like to jump to another conbtrol and not again to the first Tab.
    Unfortunately in this situation <Ctrl-Tab> doesn't generate an EVENT_KEYPRESS.
    Is there a way to handle this situation?
    Solved!
    Go to Solution.

    I don't understand why you cannot get the keypress event: I have tried to modify TabExample example installing a callback on the tab control and properly get the keypress event on Ctrl+Tab. Here the code for the tab control callback function:
    int CVICALLBACK TabCallback (int panel, int control, int event,
    void *callbackData, int eventData1, int eventData2)
    int nextCtrl, lastTab, pageIdx, virtualKey, modifierKey;
    if (event == EVENT_KEYPRESS) {
    GetActiveTabPage (panel, control, &pageIdx);
    GetNumTabPages (panel, control, &lastTab);
    lastTab--; // Zero-based index
    virtualKey = eventData1 & VAL_VKEY_MASK;
    modifierKey = eventData1 & VAL_MODIFIER_KEY_MASK;
    // Properly handle Ctrl+Tab
    if (modifierKey == VAL_MENUKEY_MODIFIER && virtualKey == VAL_TAB_VKEY && pageIdx == lastTab) {
    GetCtrlAttribute (panel, PANEL_TAB, ATTR_NEXT_CTRL, &nextCtrl);
    SetActiveCtrl (panel, nextCtrl);
    return 1; // Swallow the keypress event so that active page doesn't change
    return 0;
    Alternatively, you can handle the situation inside a panel callback:
    int CVICALLBACK PanelCallback (int panel, int event, void *callbackData,
    int eventData1, int eventData2)
    int lastTab, control, pageIdx, virtualKey, modifierKey, nextCtrl;
    if (event == EVENT_KEYPRESS) {
    if ((control = GetActiveCtrl (panel)) == PANEL_TAB) {
    GetActiveTabPage (panel, control, &pageIdx);
    GetNumTabPages (panel, control, &lastTab);
    // eventData1: a 4-byte integer consisting of 3 fields: 0x00MMVVAA
    // MM = the modifier key, VV = the virtual key, AA = the ASCII key
    // key masks are defined in userint.h
    virtualKey = eventData1 & VAL_VKEY_MASK;
    modifierKey = eventData1 & VAL_MODIFIER_KEY_MASK;
    // Properly handle Ctrl+Tab
    if (modifierKey == VAL_MENUKEY_MODIFIER && virtualKey == VAL_TAB_VKEY && (pageIdx == lastTab - 1)) {
    GetCtrlAttribute (panel, PANEL_TAB, ATTR_NEXT_CTRL, &nextCtrl);
    SetActiveCtrl (panel, nextCtrl);
    return 1;
    return 0;
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

  • (1) Firefox chews up memory - 1 GB+ over time (closing tabs doesn't help); (2) every 30 sec. or so it freezes briefly.

    2.5 GB memory, 2.8 GHz P4.
    Using FF 3.6.16. Last 2 minor upgrades happened auto. , without my permission (another irritant).
    I routinely clear the cache (all options checked off), and this has little to no effect on either #1 or #2. Whenever I restart FF, it takes less than 24 hours to get back to memory-hog state. Regardless of number of tabs - I've tested that too, even just a couple of tabs over time will see memory swallowed up.

    The battery alone is a $5 to $15 part.  Hard drives vary in cost, and depending on the iMac, they may or may not be able to install a third party hard drive, or one resold through Apple.    The resold through Apple drives tend to cost more.  This article discusses the varying successes of third party drives on iMacs:
    http://blog.macsales.com/10146-apple-further-restricts-upgrade-options-on-new-im acs 
    The labor costs depend on the store as well as the time to get the parts in stock.    Call around.

  • TextEdit Tab setting

    I write just about everything on TextEdit and have tons of documents. The problem I've been experiencing, starting back at some point but too busy to figure out what's going on, is that my TAB setting is changing while I'm typing. I'm an idiot as far as inner workings of anything... like cars.. computer etc etc. I just use it. I have no clue how to set the tab so it doesn't change on me from line to line. I need something like: "TAB SETTING HERE" or "Click here to LOCK your TAB SPACING" but I just don't see it.
    Right now it flips between slightly over 3/8" to 1/2" spacings. Sometimes some other weirdness goes on that I can't make rhyme or reason why it's doing what it's doing. It's kinda like spring loaded and I don't know when it gonna go off. All I want is the control so I can make it stop... or perhaps, I suppose, understanding of how it works. What am I doing wrong? I'm thinking pasting types etc from elsewhere is throwing the tab setting off? May be because I intermix bold types etc? I've no clue???
    Help please.

    I understand that part.
    What's happening is that TAB spacing of every 1/2" somehow changes amid typing to something like 13/32" spacing. I can see the arrows on the top ruler pointing to every 1/2" changing to every 13/32", eg the stuff that needs to be at 1 1/2" mark ends up at 1 7/32" and so on on the next line. Another words I can't lock the tab setting at every 1/2". I don't know what's causing the Tab spacing to change from every 1/2" to every 13/32"...??? How do I get around this problem? I want to be able to past text from other sources without causing havoc to my tab setting... ie if that is the cause of this problem.

  • Premiere CS5 post alt-tab freeze

    Hi all
    I have this problem with Premiere CS5 (but I had it with ALL previous versions...)
    If I import a lot of clips (let's say 100, a normal amount for a normal edit) - in this case P2 clips, but images or other format is the same, everything works fine.
    Whenever I try to switch back and forth from/to PPRO CS5 using ALT-TAB or mouse click on windows app bar, Premiere "freezes" for many seconds, sometimes MINUTES, I would say in proportion with the number of clips in my project. It seems like every time I switch back to Premiere, it loads all the clips again, or check them or something like that.
    Since going to Photoshop or another app is very frequent during editing, this is really frustrating.
    I tried on many different machines, all Quad cores with 8 gigs of RAM, so in general powerful systems, but the problem remains.
    It is not a disk read problem because Premiere SHOULD NOT READ anything switching back to it, and anyway I have fast disks and a 100 MB/S NAS.
    Something I am missing? Some hidden switch...?
    Or a terrible BUG, that continues from the beginning of the creation of Premiere?
    By the way, Windows system, at the moment Win 7 64bits, but this bug was there with Vista, XP32... etc.
    Thanks
    Valerio Oss
    PIXEL CARTOON

    Add my name to the list of having the "Not Responding" message come up every time I click anywhere outside Premier Pro.  It takes 10 seconds (sometimes longer) before Premier Pro CS5 becomes available again and attempting to work before this delay is completed causes the screen to become a white tranlucent which will change back to normal after the 10 second delay.  The Not Responding message is displayed after about 5 seconds
    The computer in question is Win7 x64 with an i950 processor, 24 GB of ram and a four drive RAID 5 configuration.
    On the good side, from what has been written here it looks like in PP CS5.5 this issue is resolved. 
    This makes having acquired PP CS5.5 a little easier to swallow.  Now if only Adobe would deliver the DVDs... Yes I know it can be downloaded, but I really don't want to download the Master Suite trial version this time while I'm waiting for the DVDs
    Cheers,
    Michael
    Ps. when editing with a file from an external RAID volume, connected via Silicon Image Sil 3132 SATALink Controller, the "Not Responding" message takes more than 13 seconds to get back to normal.

  • Image Processor Tab Missing in New Adobe Bridge CC 2014

    In the new Bridge CC you used to have a TAB under tools called Photoshop which you could run the script Image Processor for easily processing jpegs. What has happened to this and is their maybe a new way of processing jpegs to lo-res that I dont know about from tiff or jpeg or does my bridge have a problem?
    I have attached a image grab from my bridge that shows that the tab is not there. I know that you can access image processor directly from Photoshop, but they used to always be linked.

    No, it is still in Bridge CC.
    Did you uninstall Photoshop CC after installing Photoshop CC 2014? If so, that may have removed some of the Bridge integration scripts by mistake. Re-installing Photoshop CC 2014 should replace the scripts.
    and it should give the image processor tab back

  • Logical Level in Content Tab

    Hi,
    What is the use of Logical Level under Content Tab in Logical Table Source?
    Need more information, docs related to this
    Thanks,
    Satheesh

    Hi
    This logical level is useful for level bases metrics.It shows the levels in your hierarchy.We can give the level in this and in the report it shows the data for that level only.
    See this lnk, http://gerardnico.com/wiki/dat/obiee/measure_level_based
    Thanks
    Don

  • Images for tabs are not getting displayed in the page

    Hi,
    I have given images for tabs on a page. when iam applying images from the local disk, it is showing the images in edit mode. But when I view the page, it is not showing any images.
    Where should i copy the images I use in my pages. I ahev copied all the images in the images directory of portal30 in server.
    Please help.
    Murthy

    Hi,
    Please check the httpd.conf file in your server for /images alias. The /images alias will point to a directory. Copy your
    image files in that directory.
    Thanks,
    Sharmila

Maybe you are looking for

  • Empty error stack with RON

    I am trying to check out a folder using RON and am getting an empty error stack. I am able to check out folders above it but am unable to check out this folder. I need to upload a new file into the folder and am unable. I get the same empty error sta

  • XML Parser - Character Encoding

    Hi, I am trying to parse a XML document containing Korean characters. Using XSL stylesheet to generate HTML output in Java Servlet. How can i do to make it work? I'm using WintNT with IIS - ServletExec3.1 for servlet engine. Here's the error messages

  • Problem upgrading Studio 5 to JDK 1.5.0

    Running Solaris Studio with JDK 1.4.2 for many months, but having a hard time upgrading to 1.5 Error: Class file has wrong version 49.0 should be 48.0 I assume that I am somehow compiling/executing under both 1.5 and 1.4.2, but can't figure out how t

  • Since I updated to 10.7.4 boot for 5 minutes

    Hi guys, I have a problem with my iMac. I have on a second partition lion installed. Everything worked great, but since I updated to 10.7.4 booting needs about 5 minutes. Anybody who also has this problem? Or any idea what I can do? Allready checked

  • Using 'My Thoughts' App to design a poster, how do I print it onto A3 paper for uni work?

    Hi, I have only had my Macbook for a month so still getting used to it. I would like to print a poster I am making using the 'My Thoughts' App onto A3 paper - how would I go about doing this? Wold it be printing it onto A4 paper and then enlarging it