TextPANE's Y_AXIS preferredSpan not set, but textAREA's is ?

I can do
area = new JTextArea();
area.setText( "Some text" );
view = area.getUI().getRootView( area );
height = view.getPreferredSpan( View.Y_AXIS ) ;and height is set to 16.0. But if I do
pane = new JTextPane();
pane.setText( "Some text" );
view = pane.getUI().getRootView( pane );
height = view.getPreferredSpan( View.Y_AXIS );height is always 0.0. Why is this?
Interestingly,
width = view.getPreferredSpan( View.X_AXIS );does give me a value back , the same in both cases ( 54.0 in my case ).
: jay

Why is this?Check out this demo code:
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
public class UTextComponent
     **  Return the current column number at the Caret Position.
     public static int getColumnAtCaret(JTextComponent component)
          int caretPosition = component.getCaretPosition();
          Element root = component.getDocument().getDefaultRootElement();
          int line = root.getElementIndex( caretPosition );
          int lineStart = root.getElement( line ).getStartOffset();
          return caretPosition - lineStart + 1;
          int rowStart = 0;
          try
               rowStart = Utilities.getRowStart(component, component.getCaretPosition());
          catch(BadLocationException ble) {}
          return component.getCaretPosition() - rowStart;
     **  Return the current line number at the Caret position.
     public static int getLineAtCaret(JTextComponent component)
          int caretPosition = component.getCaretPosition();
          Element root = component.getDocument().getDefaultRootElement();
          return root.getElementIndex( caretPosition ) + 1;
     **  Return the number of lines of text.
     public static int getLines(JTextComponent component)
          Element root = component.getDocument().getDefaultRootElement();
          return root.getElementCount();
     **  Position the caret at the start of a line.
     public static void gotoLine(JTextComponent component, int line)
          Element root = component.getDocument().getDefaultRootElement();
          line = Math.max(line, 1);
          line = Math.min(line, root.getElementCount());
          component.setCaretPosition( root.getElement( line - 1 ).getStartOffset() );
          //  The following will position the caret at the start of the first word
          try
               component.setCaretPosition(
                    Utilities.getNextWord(component, component.getCaretPosition()));
          catch(Exception e) {System.out.println(e);}
     **  Return the number of lines of text, including wrapped lines.
     public static int getWrappedLines(JTextPane component)
          int lines = 0;
          View view = component.getUI().getRootView(component).getView(0);
          System.out.println("view: " + (int)view.getPreferredSpan(View.Y_AXIS) );
          int paragraphs = view.getViewCount();
          System.err.println("p: " + paragraphs);
          for (int i = 0; i < paragraphs; i++)
               lines += view.getView(i).getViewCount();
          return lines;
     **  Return the number of lines of text, including wrapped lines.
     public static int getWrappedLines(JTextArea component)
          View view = component.getUI().getRootView(component).getView(0);
          int preferredHeight = (int)view.getPreferredSpan(View.Y_AXIS);
          int lineHeight = component.getFontMetrics( component.getFont() ).getHeight();
          return preferredHeight / lineHeight;
     public static void main(String[] args)
          final JTextPane textComponent = new JTextPane();
//          final JTextArea textComponent = new JTextArea(5, 15);
//          textComponent.setLineWrap( true );
//          textComponent.setWrapStyleWord( true );
//          textComponent.setText("1\n2\n3\n4\n5\n6\n7");
//          textComponent.setEditable(false);
          textComponent.addCaretListener( new CaretListener()
               public void caretUpdate(CaretEvent e)
                    System.out.print
                         "Column/Line : " +
                         UTextComponent.getColumnAtCaret( textComponent ) +
                         "/" +
                         UTextComponent.getLineAtCaret( textComponent ) +
                         ", Lines : " +
                         UTextComponent.getLines( textComponent ) +
                         ", Wrapped Lines : "
                    //  It looks like the View has not yet been updated.
                    //  Add request to end of queue
//                    SwingUtilities.invokeLater( new Runnable()
//                         public void run()
                              System.out.println(
                                   UTextComponent.getWrappedLines( textComponent ) );
          JScrollPane scrollPane = new JScrollPane( textComponent );
          JPanel panel = new JPanel();
          panel.add( new JLabel( "Goto Line:" ) );
          final JTextField gotoField = new JTextField(4);
          panel.add( gotoField );
          gotoField.addActionListener( new java.awt.event.ActionListener()
               public void actionPerformed(java.awt.event.ActionEvent e)
                    UTextComponent.gotoLine(textComponent,
                         Integer.parseInt( gotoField.getText()) );
                    gotoField.setText("");
                    textComponent.requestFocus();
          JFrame frame = new JFrame( "Text Component Utilities" );
          frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
          frame.getContentPane().add( scrollPane );
          frame.getContentPane().add(panel, java.awt.BorderLayout.SOUTH);
//          frame.pack();
          frame.setSize(300, 300);
          frame.setVisible(true);
}a) Run the code as is
b) enter a single character, view = 16
c) use enter key to add a new line, view = 16
d) use enter key to add a new line, view = 32
This is inconsistent behaviour. The view should change with each new line
e) use backspace key until you are left with a single character, view = 0 ?
f) use left arrow key, view = 16
Again this is inconsistent
Now remove the comments for the code that uses the SwingUtilities.invokeLater and repeat above tests. This view seems to update normally as far as I can see.
So, I guess the answer to your question is that the view processing for JTextPane is more complicated than it is for JTextArea and some of this processing is added to the end of the event thread when the setText() method is used, so you are getting an old value.
Also, notice how my two methods for getWrappedLines are different for the JTextArea and JTextpane. You would hope/expect that the view methods would return the same values but they didn't. In this case I would consider the JTextPane to be the correct code and the JTextArea inconsistent.

Similar Messages

  • Title button not set but have no title button

    I have the error "title button not set" when checking the project, but I do not have a title button, I do have titles however, so I'm asssuming (perhaps wrongly) that it's okay to set the "title button" to 'stop'.
    Is that right?

    There are various buttons on the users remote control (for the DVD player).  You can make choices about what these will do.  If you pick "stop," when the user presses the "title" menu on their remote, the DVD will stop.  That is probably not what you want.
    Here's more about these issues from CS4 help:
    http://help.adobe.com/en_US/EncoreDVD/4.0/WSbaf9cd7d26a2eabfe807401038582db29-7f7ca.html

  • My iPad is not letting me make new calendar entries, says calendar is not set - but I'm still able to make entries on my iPhone and then that entry appears on iPad.....but then I can't edit it, or add information. Really frustrating ....it worked before.

    Hoping someone can help me with this?
    My iPad calendar is not working, yet the iPhone calendar is fine. When I make an entry into iPhone the iPad gets it ...but then I'm unable to edit or alter the entry at all.
    Really frustrating, because all worked fine up until a few days ago ...panicking now because I'm not sure I can trust my calendar (which I rely on heavily).
    If anyone has any ideas as to how to fix this bug, please reply.

    It is locked to your sisters carrier.
    She would have to ask her carrier if they unlock iPhones and if she qualifies for this service.

  • Alarm not set- but it wakes me each morning

    No alarms are set in the clock app, but an alarm goes off each morning. Anyone had this problem? How can I resolve this issue?

    Ok I have same issue too! I have my alarm set up to wake me up Mon through Fri, just for work. I also noticed it doesn't go in order by day of week!
    Clearly I think it should be Monday, Tuesday, no matter what time you want to wake up. So if I were to keep the same time, then it's fine, but say I want to get up later on Tues, then you can see how it goes to bottom! So I deleted all alarms, but still I had an alarm go off! How can an alarm go off, when no alarm is set? It's like there is a secret alarm hidden in the background! Virus on phone? iOS 8.2 issue? I downloaded 8.2 few weeks ago.
    Anna

  • In Photoshop Elements 13 I keep getting a message that says "default printer is not set"; (but it is)  therefore I can no longer print.  Just started doing this out of the blue.  Was printing just fine to start with. This question is Not Answered.

    This problem happened once before and it was related to adjusting an image size in Photoshop Organizer. I don't use the organizer anymore but this problem has resurfaced!!!

    Same problem here.
    This has happened on two individual computers both running elements 13 printing to the same printer.
    As mentioned above, the users have taken to printing using windows print and fax viewer.
    I've done a clean install of elements 13 and restarted the print spooler. no joy
    Adobe, we need a solution!!

  • WLI Application Build issues - The apt.factory.path was not set

    Hi,
    I have been trying to execute the Workshop exported Ant Script on Remote machine. In my local machine where i have access to workshop i am able to run the ant script whithout any issues. But when i try the same script on Remote machine (unix) I ma getting the below exception.
    In my application, there are two projects. One web application and one EJB project, and i am trying to makr Ear file out of this.
    If any of you have faced this issue or if you have any inputs pl help me out.
    /opt/buildserver/home/e0271019/WFM_1031_migrated_Source/Migrated_Code_With_AntScript/wfm/build.xml:340: The following error occurred while executing this line:
    /opt/buildserver/home/e0271019/WFM_1031_migrated_Source/Migrated_Code_With_AntScript/wfm/build.xml:690: The apt.factory.path was not set, but the beehive annotation processors must be on the apt factory path.
    at org.apache.tools.ant.ProjectHelper.addLocationToBuildException(ProjectHelper.java:508)
    at org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.java:397)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
    at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:357)
    at org.apache.tools.ant.Target.performTasks(Target.java:385)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
    at org.apache.tools.ant.Main.runBuild(Main.java:758)
    at org.apache.tools.ant.Main.startAnt(Main.java:217)
    at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
    at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
    Thanks
    Chandran

    Hi,
    I have been trying to execute the Workshop exported Ant Script on Remote machine. In my local machine where i have access to workshop i am able to run the ant script whithout any issues. But when i try the same script on Remote machine (unix) I ma getting the below exception.
    In my application, there are two projects. One web application and one EJB project, and i am trying to makr Ear file out of this.
    If any of you have faced this issue or if you have any inputs pl help me out.
    /opt/buildserver/home/e0271019/WFM_1031_migrated_Source/Migrated_Code_With_AntScript/wfm/build.xml:340: The following error occurred while executing this line:
    /opt/buildserver/home/e0271019/WFM_1031_migrated_Source/Migrated_Code_With_AntScript/wfm/build.xml:690: The apt.factory.path was not set, but the beehive annotation processors must be on the apt factory path.
    at org.apache.tools.ant.ProjectHelper.addLocationToBuildException(ProjectHelper.java:508)
    at org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.java:397)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
    at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:357)
    at org.apache.tools.ant.Target.performTasks(Target.java:385)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
    at org.apache.tools.ant.Main.runBuild(Main.java:758)
    at org.apache.tools.ant.Main.startAnt(Main.java:217)
    at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
    at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
    Thanks
    Chandran

  • Null/not set

    hi, I'm writing some code where I want to draw a distinction between a variable being 'blank' (ie has been set to empty) and 'not set' (hasn't been set to anything).
    In a database you could say a value is 'null' or 'not set', but in java I suspect that null actually means 'not set'. (Is this getting confusing?)
    so I'd like to be able to do this:
    bob.setSurname(null); // bob has no surname
    bob.setTitle(blank); // bob has a title, and that title is ""
    I imagine this is impossible because null is a reserved word that java does something special with (?)
    My setTitle method is expecting a String so I could create a blankString string object to pass to it. Only problem then is that I have to create blankInteger and blankDate and so on. Doesn't seem like a very elegant solution to me... I could create my own String class with a 'setEmpty()' method on it, but then I might as well be writing in C++ ;-)
    Does anyone have any better suggestions?

    hi, I'm writing some code where I want to draw a
    distinction between a variable being 'blank' (ie has
    been set to empty) and 'not set' (hasn't been set
    to anything).This vexes many SQL programmers, too. Does NULL mean that there is no value, or that it's unknown, or it hasn't been initialized yet, or isn't applicable, or ...?
    In Java, the null reference is a value that indicates that the reference does not point to an object. You have to decide what semantics to give that value. If you want null to indicate that the value hasn't been set, you need an object to indicate that the value has been set to "blank".
    In the case of a String, you could make a special String object:
    public final BLANK_VALUE = new String();
    and then use == to test for this object. Often, however, the empty String "" is used to indicate the value has been set to "blank".

  • Archive Bits Not Setting

    Hello,
    I have just noticed a strange anomaly on our NetWare 6.5 SP4 server. I'm not sure how long this has been going on.
    When some documents are created/saved on the server, the archive bit is not being set. We discovered this when a file was inadvertently deleted and while trying to restore it could not find it on our backup tapes (differential backup based on archive bit). As I searched around the various drives (both Windows and NetWare), I found that this is randomly (as far as I can tell) happening with all users, but only on our Netware server. The Windows server is fine.
    It appears to be mostly MS Office documents, probably because that is mostly what we use here, but there are some PDFs missing the archive bit too. I have tried to create several test documents and am not able to reproduce it for myself. I had another user walk through and re-create several documents (duplicating the work from the day before where archive bits were not set), but while I was watching, all archive bits were set.
    I did a search on the NetWare server for all documents created/modified since Sept 30 (our last full backup where all archive bits should have been reset). I found about 1000 documents that have been created/modified,but did not have the archive bit set. I then set the archive bit on all of them. This afternoon I re-ran that same search and came up with about 50 documents that were created/modified today that did not get the archive bit set. This represents about 25% of the files created/modified today.
    I've searched the Internet and Novell's website looking for answers but haven't had any luck.
    Has anyone else run into anything like this before?
    thanks,
    david

    UPDATE:
    The first day after I installed the updates, I had about 20 documents not get the archive bit set. That was fewer than the 100 or so I was getting per day before the updates.
    In the last week or so since that day, I have now only had a few documents not get the archive bit set during the entire week. While it is not perfect, maybe it will continue to improve.
    Thanks for all your help with this.
    david
    >>> David Hodgson<[email protected]> 10/27/2010 4:29 PM >>>
    Hello,
    I have just noticed a strange anomaly on our NetWare 6.5 SP4 server. I'm not sure how long this has been going on.
    When some documents are created/saved on the server, the archive bit is not being set. We discovered this when a file was inadvertently deleted and while trying to restore it could not find it on our backup tapes (differential backup based on archive bit). As I searched around the various drives (both Windows and NetWare), I found that this is randomly (as far as I can tell) happening with all users, but only on our Netware server. The Windows server is fine.
    It appears to be mostly MS Office documents, probably because that is mostly what we use here, but there are some PDFs missing the archive bit too. I have tried to create several test documents and am not able to reproduce it for myself. I had another user walk through and re-create several documents (duplicating the work from the day before where archive bits were not set), but while I was watching, all archive bits were set.
    I did a search on the NetWare server for all documents created/modified since Sept 30 (our last full backup where all archive bits should have been reset). I found about 1000 documents that have been created/modified,but did not have the archive bit set. I then set the archive bit on all of them. This afternoon I re-ran that same search and came up with about 50 documents that were created/modified today that did not get the archive bit set. This represents about 25% of the files created/modified today.
    I've searched the Internet and Novell's website looking for answers but haven't had any luck.
    Has anyone else run into anything like this before?
    thanks,
    david

  • HT204053 I have tried to load iCloud onto my Vista opperated pc but do not get a control panel with which to set it up. Each time I use my iTunes id to log into the iCloudI am told that it is an apple id but not set up for the Cloud. How do I get the cont

    I have tried to install iCloud on to my Windows Vista pc. No control panel is present and when I try to login to iCloud using my iTunes id, I am told that it is an Apple id but not set up for the cloud. without the control panel where do I set up my iCloud id?

    You can not setup a new iCloud account using a PC. You must use an Apple device (Mac or iPhone/iPad) to create the account, then sign into it using your PC.

  • The App Store want allow me to download new apps because I have not set up security questions.But I share an iTunes account with my friend. So if I set up the questions will my friend have to use and answer the same thing?

    The App Store want allow me to download new apps because I have not set up security questions.But I share an iTunes account with my friend. So if I set up the questions will my friend have to use and answer the same thing?

    They will have to be answered the first time when purchasing from a new computer or device.

  • HT4759 i downloaded the icloud to my pc it says to login with apple id and it says it is a valid apple id but not cloud but i cannot get the control panel for icloud to come up to set it up on my pc which runs windows 8

    i downloaded the icloud to my pc it says to login with apple id and it says it is a valid apple id but not cloud but i cannot get the control panel for icloud to come up to set it up on my pc which runs windows 8

    An update.
    From iCloud Control Panel 2.1.1 for Windows
    "iCloud Control Panel 2.1 and later includes support for Windows 8"
    but you still need to set it up on a Mac or iOS device, "Note: To create an iCloud account you need an iPhone, iPad, or iPod touch with iOS 5 or later, or a Mac with OS X Lion v10.7.5 or later."

  • I am trying to change my email address for an Apple ID and it is saying that it is already in use. I then sign in with that Apple ID and it says that the account is not set up yet, I don't want to set up the account, but I do want to use the email address

    I am trying to change my email address for an Apple ID and it is saying that it is already in use. I then sign in with that Apple ID and it says that the account is not set up yet, I don't want to set up the account, but I do want to use the email address in my original Apple ID! HELP!

    Welcome to the Apple community.
    Once you have created a rescue address, you cannot delete it, nor can you change it to the same address as used by your ID. There are numerous providers you can get additional email addresses from, such as Hotmail, Yahoo, Google etc etc.

  • HT4623 I have an ipad 2 on ops 4.3 and have just updated to 7.1 via itunes. I backed up first and have synced repeatedly but keep getting a message on my ipdad screen that the ipad is not set up - I chose the set up option restore from itunes back up

    I have an ipad 2 on ops 4.3 and have just updated to 7.1 via itunes. I backed up first and have synced repeatedly but keep getting a message on my ipdad screen that the ipad is not set up - I chose the set up option restore from itunes back up

    To free up hard drive space the best bet is to move data files that you don't need access to all the time. Likely candidates are music, video, and photos. Things like word processing and spreadsheet files can also be moved but they tend not to be very large and so don't free up much space. The problem with moving the above mentioned files is that iTunes and iPhoto need to know where the files are stored.
    Here's an article explaining how to move the iTunes folder. You can move the iPhoto library using the Finder but there is a slight complication. Start iPhoto, open the Preferences and click on the Advanced tab. The first option is "Copy items to the iPhoto Library". If this option is checked, copy the iPhoto library to your external folder (drag it from the Pictures folder to your external drive) and then delete it from your Picture folder. If this option is not checked, it is a bit more complicated and we'll need to talk a bit.

  • TS4062 my iphone 4 has mild water damage and will not sync with cable.I want to sync it over wifi to reload data I deleted during my troubleshooting, but I did not set up for wifi sync before the damage. Is there a way that this can be done now ?

    My iphone 4 has mild water damage. As a result, it will not sync with it's former XP computer with the cable. I deleted the phone's data in the troubleshooting process. I want to get it back by syncing over wifi, but I did not set up this capability before the damage occured.is there another way to initiate this feature ? I can tell that they are connecting in the cloud because an app I just downloaded on the phone is showing up in itunes on the computer.

    You don't need to access your e-mail account, just get into your Apple account and change the e-mail address. If you can't access your Apple account, then you have a bigger issue to contend with.

Maybe you are looking for

  • How many times can you upgrade your ipad mini?

    i have the ipad mini, and i would like to know, how many times you can upgrade? reason being the 3rd gerantion ipodtouch only upgrades once. for an ipad mini can i upgrade more than once, because it would be fair

  • [SOLVED] SDL audio works only under "sudo"

    I seldom play games, but when I do I always bump into a problem of no sound in SDL lib based games. There is no sound if I try to run them as a normal user. While "sudo game" (not "# game") runs the game with sound just fine. My user is in audio grou

  • Multiple doc type setting for service PR generated from Maintenance order

    Hi Gurus, My client has multiple company code and has different document type for PR and PO as per the company code. For generating the  service PR  from maintenance order system take the document type of PR defined in the config. Is it possible to d

  • Why sometimes after the sleep I can't use the Internet?

    Hello guys,I have a MacAir 13,and there is one thing a little annoying. Sometimes,when I woke my air up,it said I am connected to the wifi,but when I opened safrai,it just couldn't surf the Internet,all the link was dead. But when I restart air,every

  • Crashing on render

    I keep crashing about 15 seconds into my output to media. - Encoding Time: 00:00:17 07/10/2012 11:38:12 PM : Encoding Failed Export Error Error compiling movie. Unknown error. Is there a log I can post for help somewhere? Thanks.