How do I reduce the space between lines in a JTextComponent?

I've searched pretty thoroughly in this forum and can't find an answer.
My editor displays text fine, but I'm not happy with the space between lines. Is there any way I can reduce the overall height of each line just to close the gap a little?

Okay, I've got it worked out. I reckon it will work for my purposes although I have yet to test it in my app.
The trick is to use a negative value for the StyleConstants.setSpaceAbove(spacing2, -5.0f);The code below shows a comparison between a text pane with default spacing values and a text pane with that -5 space above value.
import java.awt.*;
import javax.swing.*;
import javax.swing.text.*;
public class TestTextPane extends JFrame
public TestTextPane()
     super("Text Pane Test: LineSpacing");
JPanel panel = new JPanel();
setContentPane( panel );
JTextPane textPane = new JTextPane();
textPane.setFont( new Font("monospaced", Font.PLAIN, 12) );
textPane.setText( "abcdefghijklmnop\none\ntwo" );
SimpleAttributeSet spacing = new SimpleAttributeSet();
StyleConstants.setLineSpacing(spacing, 0.0f);
StyleConstants.setFirstLineIndent(spacing, 0.0f);
StyleConstants.setSpaceAbove(spacing, 0.0f);
StyleConstants.setSpaceBelow(spacing, 0.0f);
StyleConstants.setUnderline(spacing, false);
StyleConstants.setItalic(spacing, false);
StyleConstants.setBold(spacing, false);
//this line sets the attributes for the text specified by the first two arguments.
textPane.getStyledDocument().setParagraphAttributes(0, textPane.getDocument().getLength(), spacing, true);
JScrollPane scrollPane = new JScrollPane( textPane );
scrollPane.setPreferredSize( new Dimension( 200, 200 ) );
//set up the comparison
JTextPane textPane2 = new JTextPane();
textPane2.setFont( new Font("monospaced", Font.PLAIN, 12) );
textPane2.setText( "abcdefghijklmnop\none\ntwo" );
SimpleAttributeSet spacing2 = new SimpleAttributeSet();
StyleConstants.setLineSpacing(spacing2, 0.0f);
StyleConstants.setFirstLineIndent(spacing2, 0.0f);
StyleConstants.setSpaceAbove(spacing2, -5.0f);
StyleConstants.setSpaceBelow(spacing2, 0.0f);
StyleConstants.setUnderline(spacing2, false);
StyleConstants.setItalic(spacing2, false);
StyleConstants.setBold(spacing2, false);
//this line sets the attributes for the text specified by the first two arguments.
textPane2.getStyledDocument().setParagraphAttributes(0, textPane2.getDocument().getLength(), spacing2, true);
JScrollPane scrollPane2 = new JScrollPane( textPane2 );
scrollPane2.setPreferredSize( new Dimension( 200, 200 ) );
panel.setLayout(new FlowLayout());
panel.add( scrollPane );
panel.add( scrollPane2);
public static void main(String[] args)
TestTextPane frame = new TestTextPane();
frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
frame.pack();
frame.setVisible(true);
}

Similar Messages

  • How do I reduce the space between the images in the fotopage?

    Hi
    I have made a Photopage - and some of the Photos are croped and when I add them to the page there is a loot of space between the one above and underneath
    look at this screen shot
    http://skitch.com/baiaz/n8un4/iweb
    or go to my photopage:
    http://web.me.com/baiaz/Adino/Galleri/Sider/UKE1.html
    Then you will see what I mean.
    Is there a way to make them more even???? So the gap is not that big when I crop the photos?

    The photogrid is square. Your pictures are rectangle. That's difficult to fit.
    To change the settings of the photogrid, click on an image.
    You can change the number of columns, the spacing between the images, the numbers of lines for the caption and the number of pictures on a page.
    It's all there.

  • How do I reduce the space between headlines in Firefox via DW?

    Hi all,
    I have a website up and running, I can send the URL to anyone who thinks s/he may be able to help me.
    The webpages look great in Explorer Internet.  However in Firefox, there's a lot of unslight gaps between the main headline, the sub-heading, etc.  And I've tried to find out why it's like that, by peering into DW's coding part, but I can't seem to see the code that influence this.  Does anyone have any idea?
    I should add that I use a template for all of these webpages, and that I've set up editable regions within that template.  I get this feeling that the way I set up the editable regions may be part of the problem, so I'm going to go and test that hunch.
    In the meantime, if any of you have run into that problem in Firefox (but not EI), and have any suggestions, I'd really appreciate it.
    Thanks,
    Alexy

    Hello Sandra,
    Thanks for providing the link. I was actually right the first time. Your issue actually falls on browser compatibilties. Firefox has a different way of interpreting paragraph - <p>... </p> tags. By default, it adds some more space.
    I am inserting a screenshot here when I edited your page in Dreamweaver:
    Instructions:
    Highlight the group of text which has an issue - "Do you need....products?*".
    Go to the Tag Inspector grid (bottom part) where you can see blurred tags like <table>, <tbody>, <tr>, ... and the bold tags <mmtinstance:editable>.
    Right-click on the <p.blurb> tag and choose Remove Tag. This means this is a paragraph tag using the "blurb" class.
    After this you will see that the formatting for the highlighted group of text has been removed.
    While the texts are still highlighted, go to Insert menu > Layout Objects > Div Tag
    In the Class input textbox, type the word blurb and click OK.
    Save the page and preview it in Firefox again.
    Feel free to reply to this post for the updates.
    Thanks and have a nice day.
    Regards,
    Christine R.
    Adobe North America Technical Support

  • How to reduce the space between to words in Scripts?

    Hello Friends,
      How can I reduce the space between to words in Scripts?
    Thanks & Regards
       Sathish Kumar

    use &ekpo-ebeln(C)& it is for reducing the space...
    if you are trying to codense the space in prog  and then want to pass that to script use
    condense ekpo-ebeln <no-gaps>.
    <no-gaps> is optional ...so as per your requirement you can use it
    regards
    shiba dutta

  • How can I adjust the space between the dividing line of the footnotes and the continuous text?

    How can I adjust the space between the dividing line of the footnotes and the continuous text?

    I want to extend the space so the dividing line does not stuck to the normal (continuous) text in my thesis. Do you have a solution? That would be perfect. Thanks a lot!

  • How do reduce the space between the front panel and the display area

    I am trying to reduce the space between the front panel and display area but i am not able to reduce the space

    A picture would be very helpful in demonstrating what you are having trouble with.
    Lacking that, I will guess.
    VI Properties >>> Windows Size
    lets you define the minimum size of a FP window.
    Well that's my guess!
    Did I win?
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • How to I increase the space between the top of tabs and the frame of the entire window? It was fine until Firefox updated

    Hello,
    How to I increase the space between the top of tabs and the frame of the entire window? It was fine until Firefox updated and since it updated it reduced the space. Now the space is too thin which makes it more difficult to move the open window frame around when I need to grab something from Desktop. Image attached.

    In the image, see how thin the space is right above the tab? It was much wider before Firefox update so if any know how to make it wider again, please let me know. Thank you
    ''troyable7 [[#question-1058550|said]]''
    <blockquote>
    Hello,
    How to I increase the space between the top of tabs and the frame of the entire window? It was fine until Firefox updated and since it updated it reduced the space. Now the space is too thin which makes it more difficult to move the open window frame around when I need to grab something from Desktop. Image attached.
    </blockquote>
    In the image, see how thin the space is right above the tab? It was much wider before Firefox update so if any know how to make it wider again, please let me know. Thank you

  • How do you change the spacing between lines of text?

    using Dreamweaver 6 how do you change the spcing between lines of text. Not seeing it as a option in the page properties menu.

    Try CSS line-height property.
    Kenneth Kawamoto
    [link removed by moderator]

  • How can I change the space between a checkbox and text all at one time? I have a lot of checkboxes in my form.

    How can I change the space between a checkbox and text all at one time? I have a lot of checkboxes in my form.

    Okay, I haven't found a way to add an extra space using Find/replace, but you might be able to add some text wrap to the check boxes that will push the text away from them.
    Open Find/Replace and click the Object tab.
    Click the Specify attributes to find button to the right of the Find Object Format: field.
    Under Basic Attributes, choose Stroke and then the Black swatch (assuming the black swatch is applied to the strokes of your check boxes). If there are no other stand-alone objects in your form with a Black stroke, this should be all you need. (If there are Black strokes on your table cells, they will be ignored.)
    Click OK
    Click the Specify attributes to change button to the right of the Change Object Format: field.
    Under Basic Attributes, choose Text Wrap & Other > Text Wrap > Type: > Wrap around bounding box (2nd button from left)
    Under Offset, set a Right offset at the distance you'd like to add (I don't know what units you use, but the 3-5 points might work for your purposes...might take some trial-and-error to get it where you want)
    Click OK
    Click Change All

  • How do I change the spacing between lines in Pages 5.5.2?  Single spacing prints more like double spacing.

    How do I change the spacing between lines in Pages 5.5.2?  Single spacing prints more like double spacing.

    In the Format panel under the Text Style tab, there is a ▸ Spacing category. Click it to open, and you will have a selector that defaults to Lines, and to the right, the ability to set your spacing in decimal values. In addition to Lines, you also have At Least, Exactly, and Between capability. You can even set exact line height  in points. Check that your Before Paragraph, and After Paragraph settings are correct for your needs.

  • How do you remove the space between the lines in your email signature?

    I have a problem with my signature in business catalyst mail.
    I have added a logo and my signature and when I send the email it looks good.
    There is the space between the lines that I want.
    But when the mail is received it looks like this:
    with too much space between each line. How do I fix this?
    Thank you in advance for you help and your time.
    Regards Winnie

    Hello,
    Well the good news is it looks like it's going to be some css and html issues the bad news (for most people) is it looks like it's going to be some css and html issues.
    Couple things.
    Are you looking at vertical or horizontal spacing?
    Region 1 in the shipped themes are used for breadcrumbs and usually have set vertical spacing and margins.
    Have you looked at the other layout examples in that application, there's 2 that show different ways of getting exact layout.
    Look at your page template there is an attribute called
    Region Table attributes
    if it looks like
    summary="" cellpadding="0" border="0" cellspacing="0" width="100%"
    change it to
    summary="" cellpadding="0" border="0" cellspacing="0"
    and see if that helps?
    If you can put an example on htmldb.oracle.com thats the easiest way to help you out, as a rule it's very hard to debug UI issues without seeing them.
    Carl

  • How Can I Tighten the Space Between Table Rows?

    I am trying to reproduce the resume I created in a different word processing application several years ago. I have created a table that lists all the work for a given employer with each row representing a different employer. I do want a little more space between text rows when I jump from one employer to the next (one row in the table to the next), but not as much as it is creating. Is there a way to tighten this?
    I like the amount of space between lines within a row just as it is.
    Martin
    OS 10.9.5
    Pages v. 5.2 (1860)

    That looks to be the idea, but adjusting the Text Inset is giving me inconsistent results from row to row. The first attached image shows the table (I've included grid lines here to help illustrate) with the default Text Inset of 4 for all cells.
    Note the consistent spacing before and after each row. Here is the same document with a Text Inset of 0 on all cells:
    Note the large gap between the first and second rows (OWN and Investigative etc.) and the extremely tight gap between the second row and third (Investigative etc. and CNBC). Then a big gap, a tight gap, two big gaps, a tight gap and a big in subsequent rows.
    I keep looking to see if I have some sort of other inconsistent formatting going on, but I can't find one. All cells have the Text set (in the style tab) to "Align text to the top of a table cell."
    Martin

  • How can i set the space between two button?

    Hello,
    I have
    <mx:HBox>
    <mx:Button label="one" />
    <mx:Button label="two" />
    </mx:HBox>
    how can i set the distance between this two compotents?
    Thanks

    quote:
    Originally posted by:
    robinbouc77
    Hi,
    you can use horizontalGap property on HBox to change the
    space between your buttons. I think the default value is 6. You can
    also use <mx:Spacer/>, but changing the gap on HBox is
    probably the cleanest way ;)
    C U
    perfect!!! works fine

  • Reducing the space between select option -Text element & Extension button

    Hi ,
    Can someone let me know is it possible to reduce the space betwwen the text element of select option & Extension button.
    i.e. is it possible to make customise  the extension button such that it is near the text element

    HI,
    You can use
    SELECTION-SCREEN BEGIN OF LINE.
      SELECTION-SCREEN COMMENT 1(10) TEXT-001.
      PARAMETERS: P1(3), P2(5).
    SELECTION-SCREEN END OF LINE.
    Only use this for single range ie from P1 to P2
    Define a range in your report and populate the range from P1 and P2.
    Regards
    Praveen

  • How do I alter the space between the Bullet and the start of a sentence?

    Hello, I have recently upgraded to Pages 5.0.1, I would like to adjust the space between the bullet and the start of the sentence without having to use space as I need to save this action as part of the template that I am working on. I know the tabs at the top adjust indent but they move the bullet too, I need to change the space between the two. Thanks in advance for the help!

    Please ignore this question, I found it, just wasn't used to the new layout of the inspector. For anyone else who is looking, the inspector is the pannel on the left, at the top click style, then at the bottom you will see bullets, click the arrow next to bullets to expand the options then adjust the "text" indent, note there are two indent options "Bullet" and "Text", "text" effects the space between the bullet and word and "bullet" effects the space between the margin and bullet.
    Now I just need to work out how to update the default font styles in new pages and I'm back to where I was six months ago.

Maybe you are looking for

  • How do we reset password for SAP* and DDIC user in SAP R/3 ECC 6.0?

    Hi, How do we reset password for SAP* and DDIC user in SAP R/3 ECC 6.0? I tried with acual method as below from client '000': DELETE FROM USR02 CLIENT SPECIIED WHERE BNAME = 'SAP*' AND MANDT = '001'. After this when I tried to logon '001' using SAP*

  • Linking Directly from a Keyword to a Specific place in a topic?

    I have a topic called 'test'. Within that topic I have the following letters... A B C ...etc, all the way thru z, each letter on their own line. I do a search on the letter M. I get the results that the letter M is in Test. Is there a way I can go di

  • Iphoto 6.0.6

    My iphoto 6.0.6 was working until I was prompted to "update the thumbnails" which I did, and now it opens but none of the menu selections work. Nothing functional is highlighted in the menus, including 'quit". so I've had to force quit. I've reopened

  • Please Help : Installing Oracle 9I R1 on RedHat Linux

    ./runInstaller Initializing Java Virtual Machine from /tmp/OraInstall0/jre/bin/jre. Please wait... SIGSEGV 11* segmentation violation Full thread dump: Monitor Cache Dump: Registered Monitor Dump: Name and type hash table lock: <unowned> String inter

  • After Oracle Upgrade to 11G - Not able to open shopping carts in SRM system

    Dear Friends, We have upgraded the Oracle to 11G on our SRM development system. Now we have an issue with opening the shopping carts from below url. http://ussapdjs00.corpnet2.com:8001/sap/bc/gui/sap/its/bbp_mon_sc?sap- client=600 But we could able t