HELP !! change the line height in JTextArea ??

can anyone tell me , how to change (set) the line height in JTextArea ???

Looking at the source code for JTextArea, the rowHeight is taken from the font's FontMetrics and is used to set the preferred size of the ta, as you can see in the following app. Also, only three properties are maintained by the default PlainDocument as shown in the output. Might be worth your while to check out JTextPane.
import java.awt.*;
import java.awt.event.*;
import java.beans.*;
import java.text.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
public class TARowHeight {
  public static void main(String[] args) {
    final CustomTextArea ta = new CustomTextArea(5,10);
    ta.addPropertyChangeListener(new PropertyChangeListener() {
      public void propertyChange(PropertyChangeEvent e) {
        System.out.println(e.getPropertyName() + " changed to " + e.getNewValue());
    ta.setLineWrap(true);
    ta.setWrapStyleWord(true);
    ta.setFont(new Font("lucida sans regular" , Font.PLAIN, 16));
    JPanel centerPanel = new JPanel();
    centerPanel.add(ta);
    SpinnerNumberModel model = new SpinnerNumberModel(20,8,36,1);
    final JSpinner spinner = new JSpinner(model);
    spinner.addChangeListener(new ChangeListener() {
      public void stateChanged(ChangeEvent e) {
        int height = ((Integer)spinner.getValue()).intValue();
        ta.setRowHeight(height);
        ta.revalidate();
        ta.repaint();
    JPanel southPanel = new JPanel();
    southPanel.add(spinner);
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(new JScrollPane(centerPanel), "Center");
    f.getContentPane().add(southPanel, "South");
    f.setSize(300,200);
    f.setLocation(400,400);
    f.setVisible(true);
    System.out.println(ta.getRowHeight());
    Dictionary names = ((AbstractDocument)ta.getDocument()).getDocumentProperties();
    Enumeration keys = names.keys();
    Enumeration values = names.elements();
    while(keys.hasMoreElements())
      System.out.println("key: " + keys.nextElement() +
                         " value: " + values.nextElement());
class CustomTextArea extends JTextArea {
  private int rowHeight;
  public CustomTextArea(int rows, int cols) {
    super(rows, cols);
  protected int getRowHeight() {
        if (rowHeight == 0) {
            FontMetrics metrics = getFontMetrics(getFont());
            rowHeight = metrics.getHeight();
        return rowHeight;
  protected void setRowHeight(int rowHeight) {
    int oldVal = this.rowHeight;
    this.rowHeight = rowHeight;
    firePropertyChange("rowHeight", oldVal, rowHeight);
}

Similar Messages

  • Can someone help me change the line width of my numbers table, its not set to thin or none and its stuck on .25. its a spreadsheet i imported from excel.

    Can someone help me change the line width of my numbers table, its not set to thin or none and its stuck on pt25. its a spreadsheet i imported from excel.

    MR,
    Apparently the import wasn't a good one.
    The best option at this point might be to start a new table. Insert a new Table, Copy the old table cell range, select the first cell in the new table and Edit > Paste and Match Style. This will throw out all the old formatting. A bit of work, but a nice clean start.
    Jerry

  • How to change the lines in a standard report

    Hello experts, i would like to change the line limits in some ot the standard repoorts, ie RFGSRRCUA and RFBILA00 how do i go about please help step by step?
    Tatenda Chaibva

    in the top of the Report..
    REPORT RFBILA00 MESSAGE-ID FR
    <i><b>                LINE-SIZE   132</b></i>
                    NO STANDARD PAGE HEADING.
    adjust this as per your need.
    A.

  • How do I change the line color in a chart in Numbers on my iPad?

    How do I change the line color in a chart in Numbers on my iPad?

    Whenever I try to shift+direct select it thinks I want to move the line, so as I shift + direct select and drag my mouse across the line (to highlight it all) it moves a chunk of the line and turns it into a near perpendicular line.
    I found the appearance window, it just says "Path" (the color I want it to be that it's not)
    "Stroke" 4pt
    "Fill" (the color I want it to be that it's not)
    "Opacity": Default
    And some other buttons. I think I'll try the help line tomorrow, I know I saw a customer service number somewhere and I'm only here because the chat was unavailable. This is only one of my 3 problems with my assignment so I'll search here for answers to the other two. Learning new things is rarely fun.

  • How do i change the line spaces?

    How do i change the line spaces?????

    CSS line-height = space between lines. 
    CSS margin-top = space above the element. 
    CSS margin-bottom = space below the element.
    h1 {
    margin:0;
    line-height: 3em;}
    p {
    margin:0;
    line-height: 1.5em
    Nancy O.
    Alt-Web Design & Publishing
    Web | Graphics | Print | Media  Specialists 
    http://alt-web.com/
    http://twitter.com/altweb
    http://alt-web.blogspot.com/

  • I changed the line of my iPhone, i can send and receive messages. I can receive messages but I cant make a call... HEEELP

    Hello, I changed the line of my iPhone 4S and now I cant make a call... I receive calls and send messages.. Please, I need help!

    What did your carrier say when you reported the problem to them?

  • How can you change your line access selection?  I have found where you can change your plan selection, but can you change the line access fee or is that a set amount?

    How can you change your line access selection?  I have found where you can change your plan selection, but can you change the line access fee or is that a set amount?

        DIVAB71,
    Great question. The line access fees for the account are a set amount and can not be changed unless you are going from a basic to a smartphone or vice versa. If you are wondering about adding the month to month discount if you are out of contract Ann154 has provided great information on how to access and add the feature.
    LindseyT_VZW
    Follow us on Twitter @VZWSupport

  • Can you change the line spacing in the legend?

    Is there a way to change the line spacing in the legend? I have a pie chart with text and I can't change the line spacing for its legend like you would in a regular text. Is there a way to change it?

    For space between each line, use the leading value in the Character pallet. For space between paragraphs, use the Space Before or Space After values in the Paragraph pallet.

  • How to change the line item storage location during the sales order creatio

    How to change the line item storage location during the sales order creatio

    Hi Kumar,
    I think you can just delete it in the sales order directly, if you are using make-to-order scenario, then there will be special stock left for the sales order as the production has been goods receipt, you need to use MM transaction move the stock to unrestricted use stock. If you are using make-to-stock scenario, there should be no further problem. If you are using assembly order, please try to reject the sales order item to see if it could fullfill your requirement.
    Regards,
    Rachel

  • How to change the line's color?

    In a linechart, if the backgroundColor of
    Application is not "#ffffff",there will be some white
    horizontal lines in the linechart. how to change the
    line's color?? thanks

    Hi, I hope this is what you are looking for:
    http://blog.flexexamples.com/2007/11/15/customizing-the-horizontal-grid-lines-in-a-flex-li nechart-control/

  • Mac Mail Issue: I was having trouble sending to hotmail accounts from my Earthlink account, they had me go into Mac Mail preferences and make changes, now Mac Mail doesn't work AT ALL - any help changing the settings back to correct Mac Mail settings? I c

    I was having trouble sending to hotmail accounts from my Earthlink account, they had me go into Mac Mail preferences and make changes (because they claimed it was Mac Mail's fault, even though the hotmail error code said it's because Earthlink is blocked by hotmail), now Mac Mail doesn't work AT ALL - any help changing the settings back to correct Mac Mail settings? I can provide a transcript of the entire tech chat session, if that will help...

    both apostrophes are used correctly, thanks
    doesn't = does not (this is called a contraction)
    it's = it is
    Mac Mail's fault = possessive
    any help with the actual issue? thanks!

  • Can the next version please allow for the line height to be zero in a text box? I can only go down to .01?

    I want to create a flipping calendar. I had this brilliant idea of putting each date 01 02 03, etc in one text box, with a hard return in between, and then set the line height to zero. Then set the type to appear one paragraph at a time. It would eliminate 20 animation steps. It worked beautifully except that I can't get the line height to set to zero. It will only go to .01. Bleh!
    So please, Can the next version allow for the line height to be zero in a text box?
    Also, separate timelines would be nice instead of one long string so it would be easier to have more than one animation happening at once.
    Just a thought.
    PS - I also noticed it would be nice to have the option of having the first line in a text box dissappear or dissolve or flip out before the next one comes in, rather than just each building in on top of each other.

    In these forums you are just talking to users, not developers. To provide your feedback, in Keynote go to Keynote Menu>Provide Keynote Feedback and send your request that way.

  • [svn:fx-4.x] 14731: change the line ending to LF so this script will run properly on Mac and Unix .

    Revision: 14731
    Revision: 14731
    Author:   [email protected]
    Date:     2010-03-12 11:06:04 -0800 (Fri, 12 Mar 2010)
    Log Message:
    change the line ending to LF so this script will run properly on Mac and Unix.  Some testsuites were breaking because this script was not executing properly on mac
    QE notes: fix for testsuites
    Doc notes: no
    Bugs: no
    Reviewer: no
    Tests run: no
    Is noteworthy for integration: no
    Modified Paths:
        flex/sdk/branches/4.x/bin/fontswf

    On reflection, it seems much easier/safer to do something like this instead...
    When running in Arch, but viewing a partition with another installation's data on it, do directory listings like this:
    ls -l | FILTER
    where FILTER is a script that pulls out the Arch-announced users and groups, converts them to numeric if necessary (according to Arch's understanding), and then stuffs back in what the other installation thinks are the symbols corresponding to those numbers. This was easy enough to do, and doesn't risk breaking anything.
    Marking as SOLVED, but I'd still welcome feedback about the different ways different distributions understand the groups I cited. It's very hard to track this info down.

  • How do I change the line spacing in DW CS5?

    My problem seemed so simple to start with. All I want to do is create a single line space in DW. When I press "Enter" at the end of a sentence I want DW to go the the next line and not start a new paragraph. I just want one line space not a double paragraph space. Is there any way to change this default spacing? I have searched all over DW Help and the forums but can't find an answer anywhere.

    Thanks. That seems to work. I was trying to write a paragraph of text and then putting a hyperlink on the next line that said "Read More Here" but the hyperlink was ending up too far away from the text is was relating to. So your advice has worked.
    Thanks again.

  • How do I change the line color in a line graph?

    I used Illustrator to create a line graph. (Not my desired option as I normally import them from R and then edit, but the textbook wanted to show that you can create graphs and edit them in Illustrator)
    Anyway, I did all of the editing except that I can't change the color of the line. My assignment requires me to match the textbook example and the textbook does not provide instructions on how to do it. I've done just about any method I can think of and the line still stays light gray. I'm almost willing to just give up and lose the points but something as simple as color can't be this hard, right? Right?

    Whenever I try to shift+direct select it thinks I want to move the line, so as I shift + direct select and drag my mouse across the line (to highlight it all) it moves a chunk of the line and turns it into a near perpendicular line.
    I found the appearance window, it just says "Path" (the color I want it to be that it's not)
    "Stroke" 4pt
    "Fill" (the color I want it to be that it's not)
    "Opacity": Default
    And some other buttons. I think I'll try the help line tomorrow, I know I saw a customer service number somewhere and I'm only here because the chat was unavailable. This is only one of my 3 problems with my assignment so I'll search here for answers to the other two. Learning new things is rarely fun.

Maybe you are looking for

  • 2006 PeopleSoft HCM GPUG Annual Conference

    2006 PeopleSoft HCM GPUG Annual Conference May 31-June 2, 2006 Marriott World Center Orlando, FL The PeopleSoft HCM Global Product Users Group (GPUG) conference is hosting this annual event specifically for multi-national organizations with operation

  • How to excluse some of g/l accounts from budget checking - BCS

    Dear Experts We are implementing Funds Management -  BCS. We request you to clarify that  how to exclude some of g/l accounts from budget checking. (Here we need to give budget for all commitment items/fund center for variance calculation, but system

  • HT5525 Help adding text to the bottom of iPhoto book pages?

    Hi - I am working on a deadline (of course) to get an iPhoto book done for my parents' anniversary. I have my photos placed, and have planned well to know how many characters can fit into each space below and next to photos in the text boxes provided

  • SetSize problem!

    hi all Is there any reason for setSize doesn�t work? i dont why, its not working for me! :-( i have a class which extends JFrame and ihv added setSize(600,500) in constructor, juzt after super(title) ! someone please help me! thanks and regards sarat

  • Namespace for a closed request

    Namespace for a closed request Hi - does anyone know how to configure a namespace that will take the customer directly to their closed request (this would be an email they would receive).  I know how to direct them to an authorization or to servicema