How can I create JEditorPane which scrolls to the bottom on every resize?

JRE 1.3.0
Included a simple frame with the only control - JEditorPane (contained within JScrollPane). Every time scroll pane size changes, attempt to scroll down to the end of JEditorPane is made.
The problem is: although everything works 9 times of 10, sometimes editor is scrolled almost to the end, sometimes - to the very top. On the next resize editor is scrolled correctly.
I think, there are some delayed layout recalculations inside SWING which prevent JEditorPane and/or JScrollPane from knowing actual size.
Is it possible to force JEditorPane+JScrollPane pair to update dimensions? ( explicit call to doLayout() does not fix anything )
Thanks
public class TestFrame extends JFrame
BorderLayout borderLayout1 = new BorderLayout();
JScrollPane jScrollPane1 = new JScrollPane();
JEditorPane jEditorPane1 = new JEditorPane();
public TestFrame()
try
jbInit();
catch(Exception e)
e.printStackTrace();
private void jbInit() throws Exception
this.getContentPane().setLayout(borderLayout1);
jEditorPane1.setContentType("text/html");
jEditorPane1.setText("test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test ");
jScrollPane1.addComponentListener(new java.awt.event.ComponentAdapter()
public void componentResized(ComponentEvent e)
jScrollPane1_componentResized(e);
this.getContentPane().add(jScrollPane1, BorderLayout.CENTER);
jScrollPane1.getViewport().add(jEditorPane1, null);
void jScrollPane1_componentResized(ComponentEvent e)
Dimension size = jEditorPane1.getPreferredSize();
jEditorPane1.scrollRectToVisible( new Rectangle(0, size.height, 0, 0) );
System.out.println("preferred height=" + size.height);
}

Seen this thread?
Return to previously viewed page

Similar Messages

  • How can I create a status bar at the bottom of a window ?

    I would like to create a status bar at the bottom of my main window similiar to "Internet explorer" has. I thought of using a tool bar but I can't see how to keep it positioned at the bottom of the window when the window is resizable. Any other ideas on how to do this the bar only needs to contain a small amout of text and maybe an icon or two.

    CVI doesn't have a status bar control on UI element like the one available in Visual Studio++. The best way to replicate this is most like through a string control that is resized and positioned to remain at the bottom of the window and colored to look appropriately. I have also seen the combination of a decoration and a text message used.
    Best Regards,
    Chris Matthews
    Measurement Studio Support Manager

  • How can I create an internal space from the border in every cell in a table?

    How can I create an space between the text contents and the border inside in every cell in a table in Pages?

    Change the Inset margin in the Inspector palette > T tab > Text

  • How can I implement a status bar at the bottom of a resizable application?

    Hello all,
    I am a JavaFx newbie and I am implementing an application (a Sokoban game), with a menu at the top of the frame and a gaming area covering the rest of the frame. To support the game, I have to load images at certain positions in the gaming area.
    The game also includes a level editor with another menubar and where images are set to other positions.
    I implemented this in another view, swiching from the game mode to the level editor mode and vice versa is just done by setting the other view visible. Up to now this works, here the important statements building these details:
    Group root = new Group();
    gameView = new Group(); // for gaming mode
    le_view = new Group()   // for level editor mode
    MenuBar gameMenubar = new MenuBar();
    Menu menuGame = new Menu(bundle.getString("MenuGame"));
    ... building the menu items and menues ...
    gameView.getChildren().add(gameMenubar);
    ImageView buildingView[][] = new ImageView[22][22];
    for (nCol = 0; nCol < 22; nCol++) {
        for (nRow = 0; nRow < 22; nRow++) {
            buildingView[nCol][nRow] = new ImageView();
            buildingView[nCol][nRow].setX(nCol * 26 + 5);
            buildingView[nCol][nRow].setY(nRow * 26 + 40);
            gameView.getChildren().add(buildingView[nCol][nRow]);
    gameView.setVisible(true);
    root.getChildren().add(gameView);
    ... same stuff to build the le_view ...
    le_View.setVisible(false);
    root.getChildren().add(le_View);
    Scene scene = new Scene(root, 800, 600, Color.CORNSILK); Now I want to introduce a status bar at the bottom of the frame, which of course has to follow the bottom of the frame, if it is resized. And of course the menu and the status bar should not grow vertically, if the height of the frame is increased.
    The implementation seems to be easy with StackPane for the frame and one BorderPane for each mode.
    For the first step I only tried implementing the game mode with only one BorderPane (just setting the menu, the gaming area and the status bar each into a HBox and setting these three HBoxes at the top, into the center and at the bottom). I also tried this via GridPane and via VBox; I always get any erroneous behaviour:
    Either the menubar is visible, but the menus do not pop up the menu items, or the anchor point of the menu and of gaming area are set 100 pixels left of the left frame border and move into the frame when the frame width is increased, or the menu is set 20 pixels below the top of the frame, or HBox with the menu grows when the frame height is increased, so that the anchor point of the gaming area moves down.
    Can you describe me a correct construction of such a frame? Thanks in advance.
    Best regards
    Gerhard

    Hello Gerhard,
    Glad the code helped, thanks for a fun layout exercise.
    For the draft code I just pulled an icon off the internet over a http connection.
    If you haven't done so already place any icons and graphics you need local to your project, so that resource lookups like:
    Image img = new Image("http://www.julepstudios.com/images/close-icon.png");become
    Image img = new Image("close-icon.png");then performance may improve.
    Another possible reason for your performance problem could be that when you use a vbox, the vbox content can overflow the area of the borderpane center and might be sitting on top of the menu pane, making you unable to click the menu (which is what happens to me when I try that with the draft program with the vbox wrapping mod, then resize the scene to make it smaller). This was a trick which caught me and the reason that I used a Group originally rather than a vbox. I found a vbox still works but you need to tweak things a bit. The trick I saw was that the order in which you add stuff to the borderpane is important. The borderpane acts like a stack where the last thing added floats over the top of everything else if you size the scene small enough. For your project you want the menu on top always, so it always needs to be the last thing added to the borderpane, but when you swap in the level pane for the game pane, then back out again, the game pane can end up on top of the menu which makes the menu seem like you can't click it (only when the scene is sized small enough). It was quite a subtle bug which took me a little while to work out what was happening. For me the solution was to add just one vbox to the center of the border, and then swap the game pane and the level editor in and out of the vbox, that way the center of the layout always stayed behind the menu bar and the status bar.
    I added some revisions to reflect the comments above and placed some comments in the code to note what was changed and why.
    public class SampleGameLayoutRevised extends Application {
      public static void main(String[] args) { Application.launch(args); }
      public void start(Stage stage) throws Exception {
        final BorderPane gameLayout = new BorderPane();
        final Group gameView = new Group();
        final MenuBar gameMenubar = new MenuBar();
        final Menu gameMenu = new Menu("Mode");
        final VBox centerView = new VBox();
        centerView.setStyle("-fx-background-color: darkgreen");  // we set a background color on the center view to check if it overwrites the game menu.
        MenuItem playGameMenu = new MenuItem("Play Game");
        MenuItem levelEditMenu = new MenuItem("Edit Levels");
        gameMenu.getItems().add(playGameMenu);
        gameMenu.getItems().add(levelEditMenu);
        gameMenubar.getMenus().add(gameMenu);
        final StackPane levelEditView = new StackPane();
        levelEditView.getChildren().add(new Text("Level Editor"));
        ImageView buildingView[][] = new ImageView[22][22];
        Image img = new Image("http://www.julepstudios.com/images/close-icon.png");  // use of http here is just for example, instead use an image resource from your project files.
        for (int nCol = 0; nCol < 22; nCol++) {
          for (int nRow = 0; nRow < 22; nRow++) {
            ImageView imgView = new ImageView(img);
            imgView.setScaleX(0.5);
            imgView.setScaleY(0.5);
            buildingView[nCol][nRow] = imgView;
            buildingView[nCol][nRow].setX(nCol * 20 + 5);
            buildingView[nCol][nRow].setY(nRow * 20 + 40);
            gameView.getChildren().add(buildingView[nCol][nRow]);
        final VBox statusBar = new VBox();
        final Text statusText = new Text("Playing Game");
        statusBar.getChildren().add(statusText);
        statusBar.setStyle("-fx-background-color: cornsilk"); // we set a background color on the status bar,
                                                              // because we can't rely on the scene background color
                                                              // because, if the scene is sized small, the status bar will start to overlay the game view
                                                              // and if we don't explicitly set the statusBar background the center view will start
                                                              // to bleed through the transparent background of the statusBar.
        gameLayout.setCenter(centerView); // we add the centerview first and we never change it, instead we put it's changeable contents in a vbox and change out the vbox content.
        gameLayout.setBottom(statusBar);
        gameLayout.setTop(gameMenubar);   // note the game layout is the last thing added to the borderpane so it will always stay on top if the border pane is resized.
        playGameMenu.setOnAction(new EventHandler<ActionEvent>() {
          public void handle(ActionEvent event) {
            centerView.getChildren().clear();  // here we perform a centerview vbox content swap.
            centerView.getChildren().add(gameView);
            statusText.setText("Playing Game");
        levelEditMenu.setOnAction(new EventHandler<ActionEvent>() {
          public void handle(ActionEvent event) {
            centerView.getChildren().clear();  // here we perform a centerview vbox content swap.
            centerView.getChildren().add(levelEditView);
            statusText.setText("Editing Level");
        playGameMenu.fire();
        Scene scene = new Scene(gameLayout, 800, 600, Color.CORNSILK);
        stage.setScene(scene);
        stage.show();
    }Other than that I am not sure of a reason for the slowdown you are seeing. In my experience JavaFX has been quick and responsive for the tasks I have been using it for. Admittedly, I just use if for a bunch of small trial projects, but I've never seen it unresponsive for a minute.
    - John

  • How can i create an indicator to read the RMS value of my FFT using FFT Spectrum (Mag-Phase).vi

    Hai to all,
    how can i create an indicator to read the RMS value of my FFT using FFT Spectrum (Mag-Phase).vi.
    as u can see in my block diagram(attached), i can use statistic to read the RMS value for the data but i cant's use it on the FFT Spectrum (mag-Phase).vi .
    Thank you for helping.
    Attachments:
    block diagram.jpg ‏48 KB

    hafizzuddin wrote:
    thank you for the opinions, for now i am not using any express Vi..
    In the long run you will benefit from this. Anyway is your problem solved, or do you need more help?
    Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
    (Sorry no Labview "brag list" so far)

  • How can i create multiple accounts but use the same itunes?

    how can i create multiple accounts but use the same itunes?

    Hi iCloud is Making Me Go Crazy,
    You will need to create a new Apple ID for your GameCenter and iCloud services.  You can continue to use the current Apple ID you share with your Mom for access to iTunes Store purchases if you wish. 
    Using your Apple ID for Apple services
    http://support.apple.com/kb/HT4895
    Frequently asked questions about Apple ID
    http://support.apple.com/kb/HT5622
    Cheers,
    - Judy

  • How can i create a new item in the app "health"?

    how can i create a new item in the app "health"? I need a field for documentation of "Waist-to-height ratio", exactly for "circumference".
    It's a matter of common knowledge, that the Waist-to-height ratio (WHtR) has more significance then the Body-Mass-Index (BMI).

    If you mean you want to change a color of a calendar category or create a new one, you cannot do that, what is pre-loaded is what you get and cannot be edited.

  • How can I know in which Tables are the fields stored

    Hi,
    In transaction FSE3 Display Financial Version
    Statement Version, if I drilldown in details, I can
    see Item No, Chart of Acc, From Accountm To Account D,
    C.
    when I do a F1 on the fields, I can see that it is a
    structure. How can I know in which Tables are the
    fields store?

    Hi Ankit,
    There are no rules or guidelines for finding the table but i will share some of the tips used generally.........but i am not sure if we can do it for a tree structure..but try anyways....
    Double click on the structure name seen on the F1 pop up window...
    in the structure screen, try to analyse the field which is very important something like a key in that set of fields or do the same for the fields which we feel are more important,then click on the domain for that field....once in the domain..click on the "where used list for the domain" on the top...
    it will display a pop up -> select only "table" and then press "Tick/OK"..A list will be displayed with the data element and table name ..from this we need to find out the right one we need either by going for text of the table or going through each and every one
    It takes time but does the job.....
    Regards
    Byju

  • How can i create my own file from the Adobe Export PDF to Word ?

    How can I create my own file from the file of the Adobe Export PDF to Wodrd?

    If there is handwritten content in your PDF then ExportPDF can't convert that to word.
    ~Deepak

  • How can i creat CRC 32 CHECK WITH THE lookup table as attached.

    how can i creat CRC 32 CHECK WITH THE lookup table.attached
    i creat one,but not match the result number C++ version
    result number C++ version:
    FE 00 18 02 40 1E 65 43 00 03 E8        CRC32=>78 1F E9 06
    FE 01 18 02 40 1E 65 43 00 03 E8        CRC32=>F8 8F 49 61
    FE 02 18 02 40 1E 65 43 00 03 E8        CRC32=>7D FF B4 7F

    due to some reason i can not attach the table.but you can find it herehttp://lavag.org/topic/15325-crc32/,it in the CRC.llb 84.03K =>CRC-32 Table.ctl thanks a lot

  • How can I add a black border at the bottom of a photo?

    How can I add a black border at the bottom of a photo?

    Just curious: Why whould you want to add navigation Rules at run time. I believe the navigation rules should be set to begin with - "by s/w Architect Design".
    Else you can always use Redirect / Forward.

  • How can i create table which in use

    Dear all,
    How can i create a index on table which have much dml any time?

    In 10g :
    The CREATE ONLINE waits for existing transactions to commit before it can proceed. Once it starts, it uses a log table (MV Log) to track subsequent changes (i.e. it allows concurrent DML once it has started). At the end of the operation, it encounters another wait if there are existing transactions as it has to sync changes from the MV Log to the index.
    Here's an explanation by Jonathan Lewis : Re: Alter Index Rebuild Online
    In 11g :
    There's an improvement in that only the transactions that were active at the instant when the CREATE .. ONLINE was issued are the ones it waits for. It does not have to wait on subsequent transactions.
    Here's an explanation by Richard Foote : http://richardfoote.wordpress.com/2008/02/11/index-create-and-rebuild-locking-improvements-in-11g-ch-ch-ch-changes/
    Hemant K Chitale

  • UWL Help - How can i create my own task within the Enterprise Portal

    Dear all,
    I am currently working with UWL .
    I have tried the customization and those stuffs associated with UWL , and it is working properly.
    My current issue is , how can create my own task within the Portal ( not using Ad Hoc  Workflow , which is present in Portal) ?.
    If i can create my own task within portal by API or using another method , then How can i add that task link within the drop down box that is present in the Collaboration launch pad and Mytask Workset.?
    Is there any API regarding  UWL (which is useful for creation of custom tasks in Portal using Developer Studio by means of Portal Application Creation) ?
    How can i add that custom task in the drop down ?.
    I have tried the customization of existing UWL.
    I shall be grateful to those who can help me to solve this issue with links regarding the  solution of my problem's.
    with regards
    Kishor Gopinathan

    Hi Kishore,
    I am trying to do the same thing. When i am creating Collaboration Task, it has standard templates in the dropdown like "Single Step" and "Multi-Step" etc., If i want to create my own Custom Task Template and display in that dropdown, how can i do that? Your help is really appreciated.
    Thanks
    Vijay

  • How can I create an audio CD from the audio only portion of my iMovie?

    Hello, I brought in about 50 min of Digital video into iMovie, I separated (split) the audio from the video, I unlocked the audio, I deleted the video, and now I want to just create an audio CD from the audio that is left.
    Can I do this? and if yes how? If I can not, how can I create an Audio CD from on my G5 off a tape on my digital camcorder?
    Any help would be apprecaited.

    This is how:
    Go to:
    'File'
    'Share'
    'Quicktime'
    'Expert Settings'
    'Audio as AIFF' or pick your brand of compression.
    Drag and drop the resulting file into iTunes.
    Enjoy!
    P.S. - You didn't need to delete the video but I think that'll be okay.

  • How can I create side bars without cropping the image?

    I want to create side bars because I am projecting in an vertical panel, but if I crop the image them I only get the middle part of it.
    How can I create side bars in an way that I can still move the image inside?

    On a Video Track directly above the clip(s) you want to have behind the side bars, place a clip of Color (or whatever you want to use for your sidebars).
    Now go to the Effects Tab > Matte >Mask Shape and drag the Mask Shape filter to the Color clip you have placed on the timeline.
    Double click on the clip to open it in the viewer, and click on the Filters Tab.
    Click Invert Box, and adjust the shape to get the side bars you want.
    And now the clip(s) that are beneath this effect will have the side bars and be independent of it, so that you can move them around.
    MtD

Maybe you are looking for

  • Displays no longer recognised, it is my video card?

    I have two Dell 22" widescreen monitors, and two computers plugged into both them via the DVI and VGA inputs. One is a 2x3.2 GHz Quad-Core Intel Xeon Mac Pro and the other is an older G5 PowerPC, both are running Leopard, the G5 is on 10.5.4, the Mac

  • HTTP_RESP_STATUS_CODE_NOT_OK

    Hi All, When I place any source file for processing, the message ends with the below error in MONI. <SAP:Code area="INTERNAL">HTTP_RESP_STATUS_CODE_NOT_OK</SAP:Code>   <SAP:P1>401</SAP:P1>   <SAP:P2>Unauthorized</SAP:P2> <SAP:Stack>HTTP response cont

  • Page loads flash white DW CS3

    Dear Folks, In MX 2004, this code would keep the page BLACK during loading. Now in DW CS3 the page flashes WHITE while loading. No good. What to do? Thanks for any help. Here is the code I used.

  • Want to learn how to use "serializable"

    Hello, everyone! I have never used "serializable" function of Java before. After reading API specification of java.sun.com and some tutorials of java.sun.com dealing with "serializable", I become more puzzled. I just want to know how to use the basic

  • Small Workgroup Printer Recommendation

    Hi, I currently run an office of 6 people; 2 on Macs, the rest on XP, all on a LAN (but no server, as yet). Each desk has an inkjet printer. This is costing us £600+ per year. I'd like to move us all off of these "cheap to buy, but dear to run" print