scroll pane cannot align its content

When a node (Group for example) is added in a scrolling pane, the scroll pane automatically align the node to the left upper corner of the content area of the scroll pane. How can I customize the alignment of the node (Middle center for example) in the scroll pane. When the size of the node is scaling greater than the size of the pane to scroll bar scroll the scroll pane is displayed and if the node size is shrinking, and there the size becomes smaller that the scroll pane is then the node is aligned on the Community Center. It seems do not take effect if I replace layoutChildren method of the scroll pane and set layoutX and one property of the node.
If anyone can give me some clue?
Thank you

ScrollPanes are a bit tricky to use. They line up not happy, you must use layout managers to do or you need to provision yourself with shapes in groups using absolute coordinates or translations. ScrollPane sets there own viewport associated coordinated and you need to provision your content in this window.

How can I customize the alignment of the node (Middle center for example) in the scroll pane.

The layoutBoundsInParent of the node, get the viewportBounds of scrollpane and perform the conversion of the node, such as the center of the node is at the center of the viewportBounds (requires a bit of simple math to do this) by adding listeners on each property.

When the size of the node is scaling greater than the size of the pane to scroll bar scroll the scroll pane is displayed and if the node size is shrinking, and there the size becomes smaller that the scroll pane is then the node is aligned on the Community Center.

Similar to above, come to work with these properties.

Not exactly a direct answer to your question, but you can try to play with the code after if you like Saludon. This is something I wrote to learn about JavaFX layoutbounds system. Resizing of the scene and activating / deactivating elements on and outside will allow you to see the scroll pane. View limits listeners show you properties that you are interested in getting the desired effect.

import javafx.application.Application;
import javafx.beans.value.*;
import javafx.event.*;
import javafx.geometry.Bounds;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.effect.DropShadow;
import javafx.scene.layout.*;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.*;
import javafx.stage.Stage;

public class LayoutBoundsScrollableAnchorPane extends Application  {
  // define some controls.
  final ToggleButton stroke    = new ToggleButton("Add Border");
  final ToggleButton effect    = new ToggleButton("Add Effect");
  final ToggleButton translate = new ToggleButton("Translate");
  final ToggleButton rotate    = new ToggleButton("Rotate");
  final ToggleButton scale     = new ToggleButton("Scale");

  public static void main(String[] args) { launch(args); }
  @Override public void start(Stage stage) throws Exception {
    // create a square to be acted on by the controls.
    final Rectangle square = new Rectangle(20, 30, 100, 100); //square.setFill(Color.DARKGREEN);
    square.setStyle("-fx-fill: linear-gradient(to right, darkgreen, forestgreen)");

    // show the effect of a stroke.
    stroke.setOnAction(new EventHandler() {
      @Override public void handle(ActionEvent actionEvent) {
        if (stroke.isSelected()) {
          square.setStroke(Color.FIREBRICK); square.setStrokeWidth(10); square.setStrokeType(StrokeType.OUTSIDE);
        } else {
          square.setStroke(null); square.setStrokeWidth(0.0); square.setStrokeType(null);
        }
        reportBounds(square);
      }
    });

    // show the effect of an effect.
    effect.setOnAction(new EventHandler() {
      @Override public void handle(ActionEvent actionEvent) {
        if (effect.isSelected()) {
          square.setEffect(new DropShadow());
        } else {
          square.setEffect(null);
        }
        reportBounds(square);
      }
    });

    // show the effect of a translation.
    translate.setOnAction(new EventHandler() {
      @Override public void handle(ActionEvent actionEvent) {
        if (translate.isSelected()) {
          square.setTranslateX(100);
          square.setTranslateY(60);
        } else {
          square.setTranslateX(0);
          square.setTranslateY(0);
        }
        reportBounds(square);
      }
    });

    // show the effect of a rotation.
    rotate.setOnAction(new EventHandler() {
      @Override public void handle(ActionEvent actionEvent) {
        if (rotate.isSelected()) {
          square.setRotate(45);
        } else {
          square.setRotate(0);
        }
        reportBounds(square);
      }
    });

    // show the effect of a scale.
    scale.setOnAction(new EventHandler() {
      @Override public void handle(ActionEvent actionEvent) {
        if (scale.isSelected()) {
          square.setScaleX(2);
          square.setScaleY(2);
        } else {
          square.setScaleX(1);
          square.setScaleY(1);
        }
        reportBounds(square);
      }
    });

    // layout the scene.
    final AnchorPane anchorPane = new AnchorPane();
    AnchorPane.setTopAnchor(square,  0.0);
    AnchorPane.setLeftAnchor(square, 0.0);
    anchorPane.setStyle("-fx-background-color: cornsilk;");
    anchorPane.getChildren().add(square);

    // add a scrollpane and size it's content to fit the pane (if it can).
    final ScrollPane scrollPane = new ScrollPane();
    scrollPane.setContent(anchorPane);
    square.boundsInParentProperty().addListener(new ChangeListener() {
      @Override public void changed(ObservableValue observableValue, Bounds oldBounds, Bounds newBounds) {
        anchorPane.setPrefSize(Math.max(newBounds.getMaxX(), scrollPane.getViewportBounds().getWidth()), Math.max(newBounds.getMaxY(), scrollPane.getViewportBounds().getHeight()));
      }
    });
    scrollPane.viewportBoundsProperty().addListener(
      new ChangeListener() {
      @Override public void changed(ObservableValue observableValue, Bounds oldBounds, Bounds newBounds) {
        anchorPane.setPrefSize(Math.max(square.getBoundsInParent().getMaxX(), newBounds.getWidth()), Math.max(square.getBoundsInParent().getMaxY(), newBounds.getHeight()));
      }
    });

    // layout the scene.
    VBox controlPane = new VBox(10);
    controlPane.setStyle("-fx-background-color: linear-gradient(to bottom, gainsboro, silver); -fx-padding: 10;");
    controlPane.getChildren().addAll(
      HBoxBuilder.create().spacing(10).children(stroke, effect).build(),
      HBoxBuilder.create().spacing(10).fillHeight(false).children(translate, rotate, scale).build()
    );

    VBox layout = new VBox();
    VBox.setVgrow(scrollPane, Priority.ALWAYS);
    layout.getChildren().addAll(scrollPane, controlPane);

    // show the scene.
    final Scene scene = new Scene(layout, 300, 300);
    stage.setScene(scene);
    stage.show();

    reportBounds(square);
  }

  /** output the squares bounds. */
  private void reportBounds(final Node n) {
    StringBuilder description = new StringBuilder();
    if (stroke.isSelected())       description.append("Stroke 10 : ");
    if (effect.isSelected())       description.append("Dropshadow Effect : ");
    if (translate.isSelected())    description.append("Translated 100, 60 : ");
    if (rotate.isSelected())       description.append("Rotated 45 degrees : ");
    if (scale.isSelected())        description.append("Scale 2 : ");
    if (description.length() == 0) description.append("Unchanged : ");

    System.out.println(description.toString());
    System.out.println("Layout Bounds:    " + n.getLayoutBounds());
    System.out.println("Bounds In Local:  " + n.getBoundsInLocal());
    System.out.println("Bounds In Parent: " + n.getBoundsInParent());
    System.out.println();
  }
}

Tags: Java

Similar Questions

  • TBird seems to have lost the location of the Inbox and cannot view its contents

    "After the judgment which follows ' not compaction", the contents of the Inbox for one of my accounts has disappeared. Do right click on properties returns an empty location box. Repair does not work. It was about 50-75 e-mails in the box. Make a left click on the Inbox starts a search without end. is it possible to save what was there (the other records of this account are OK).

    Hotmail account or outlook.com ?

  • Add a Flash page scroll pane?  Scroll up/down

    im confused, someone told me you cannot scroll the page up and down, but I just saw a model that has

    http://ActiveDen.NET/item/XML-blog-w..._preview/36641

    Any idea on how I would put that in my work?
    Y at - it a tutorial or something im missing?
    Thank you

    The simplest solution is to simply incorporate the Flash animation in the table. The browser will add an if necessary scroll bar. If you really, really want to do this in Flash, you can create a Flash animation to the size of the table space. Then add a Flash animation scroll pane and place the content of the Flash animation in this scroll pane. I have absolutely no idea why you want to do.

  • Cannot inspect the contents of an iframe

    I develop a Facebook app and would like to be able to view the content of the iframe (my app) FB through edge inspect. When I inspect the code on my iPad, I'm able to do all the way up to the iframe cannot see its contents. Any thoughts on what I am doing wrong?

    Thank you

    Yes. Facebook is load our app from another area in the iframe. I could find a way around the problem of the iframe displaying our app directly in a browser without all the dressings of the Facebook page. I wanted to just make sure I was not doing anything wrong.

    Thanks for your help,

    Mike

  • Button to access within a scroll pane?

    I've set up a scroll pane component and the content of it is a layout of images that are buttons.

    Name of the scroll pane is "mc_pane2".

    Class content is "MyContent".

    And the instance name of the button is 'FloraLytell_btn' (it is essensially a mc with TweenLite code in it to roll over and spread the effects)

    I'm not able to determine what would be an access code to a button in the scroll pane. Here's what I've tried and it doesn't work.

    mc_pane2. MyContent.FloraLytell_btn.addEventListener (MouseEvent.CLICK, onClick_floralytellPopUp);

    function onClick_floralytellPopUp(event:MouseEvent): void {}

    gotoAndPlay ("floralyte2pp");

    }

    Try to launch the content as a MovieClip (the compiler refuses to accept that content is a DisplayObject without explicitly telling you)...

    TweenLite.to (MovieClip (mc_pane2.content). FloraLytell_btn, 1, {x: 200});

  • After I restart my iMac and double-click on the hard drive, a pop up appears with this message: 'the 'Hard drive' file cannot be opened because you don't have permission to view its contents.'.  What is the problem?

    After I restart my iMac and double-click on the hard drive, a pop up appears with this message: 'the 'Hard drive' file cannot be opened because you don't have permission to view its contents.'.  What is the problem?

    Is the name of an external drive or internal one?

  • The visible property works in content within a scroll pane?

    I have google searche and asked for a solution, but I can't mc._visible = false: or = true; work inside a scroll pane. I have several bubbles placed on a clip that is referenced by the scroll pane. I want the ToolTip to display the mouse on an affected area and disappear on mouse out. This code does not work:

    / * menu * /.
    sp.content.menuTxt._visible = false;


    sp.content.menux.onRollOver = function()
    {
    sp.content.menuTxt._visible = true;
    TPI Content.MenuX._alpha = 50;
    }

    sp.content.menux.onRollOut = function()
    {
    sp.content.menuTxt._visible = false;
    TPI Content.MenuX._alpha = 0;
    }

    But if I move the movie clip to the main stage and copy the code next works:


    / * menu * /.
    menuTxt._visible = false;


    sp.content.menux.onRollOver = function()
    {
    menuTxt._visible = true;
    TPI Content.MenuX._alpha = 50;
    }

    sp.content.menux.onRollOut = function()
    {
    menuTxt._visible = false;
    TPI Content.MenuX._alpha = 0;


    }
    There are some of the affected areas and ToolTips in the clip, and they are also video clips. Am I hitting against a limitation? I found a few references to the depth of clips with regard to scrolling but component which was confusing.

    The only reason why I don't see why the menuTxt would not work inside the scrollpane would be if he was missing his name of the instance.  I say this because to take your code and recreate what I can make the drawing or model and see it work in accordance with what the code told him to do.   It works according to the code, so if you see that it does not work by what you expected, it says not to do everything that it is.   Here is a link to the file...

    http://www.nedwebs.com/Flash/AS2_ScrollPane_MC.fla

  • SceneBuilder - how to anchor a TextArea in a scroll pane

    TextArea will not take on the size of the Scrollpane parent in Scenebuilder.

    Cannot find how to define it, no option anchor.

    This also applies to: HTMLEditor and the text box.

    TextArea comes with it's own scrollbars even when; It is not clear why you would need to put the text box in a scroll pane at all.

    In general, you can set the properties fitToHeight and fitToWidth on the ScrollPane; they will try to size height and width, respectively, of the content to the corresponding dimension of the scroll pane. You will find under "Available" when you select the ScrollPane.

  • Help get the overthrow of the headphones to work in a scroll pane

    In AS2, how can I get a roll on listner in an MC inside a scrolling pane to display a ToolTip MC on the scene outside the scroll pane? I use the following code in the main time line to display the ToolTip, and it doesn't seem to work:

    //****Sel******//

    selectionTxt._visible = false;
    Sel.onRollOver = function()
    {
    selectionTxt._visible = true;
    }

    Sel.onRollOut = function()
    {
    selectionTxt._visible = false;
    }

    Any idea would be appreciated

    IF you load the library via its link ID, then the following may work...

    selectionTxt._visible = false;

    sp.content.Sel.onRollOver = function()
    {
    selectionTxt._visible = true;
    }

    sp.content.Sel.onRollOut = function()
    {
    selectionTxt._visible = false;
    }

  • iTunes cannot read the contents of the iPhone "iPhone 6 more»

    Please help because I can not backup my iPhone 6 Plus for my iMac and iTunes asks me to wipe it.

    When I connect the iPhone 6 Plus for the cable of the lightning, he says this: -.

    "iTunes cannot read the contents of the iPhone" IPhone Steve 6 + ".." Select the summary in the iPhone preferences tab and click on restore to restore the iPhone to factory settings. »

    The last back up, I've done was there a little more than 12 months and is an older version of iOS also so if I do a restore of the backup, it will be bad and lacks important information.

    Since then, I upgraded my iMac to El Capitan and updated my iPhone to iOS9.3.2 (just be updated to 9.3.3 now)

    System & software Specs are as follows:

    iMac 27 "V10.11.6 El Capitan (15G 31)

    iTunes V12.4.2.4

    iOS9.3.2

    Any help would be thank you very much.

    Please see the comment by David Lewis21 in this discussion of the CSA. I have not tested its solution, I can't vouch for it, and I have no other information. Try at your own risk. If you don't want to take that risk, I suggest that you contact the Apple Support.

  • How to set dynamically scroll pane?

    Hai...

    I'm trying to get the text of the xml tag and put it in the scrollpane but Idont know how to set dynamically in scrollpane... someone has idea... Please help me

    Thank you

    Dembélé

    I found the solution... Scroll pane is allocated dynamically when content is dynamic

  • Image in the scrolling pane does not appear correctly.

    Hello. I encountered this problem that my image and text inside my project is not correctly displayed after I added the scroll pane. The images and text were positioned on the left side of the project. It is supposed to be justified as usual. For some reason, continue to get my video clips alongside my scrollable area. So my image that had been displayed are displayed halfly. Someone knows how to fix this?

    It rests about alignment of the MovieClip, you will need to make at the top left:

    Double-click on the movieClip > select and combine everything (ctrl-A and ctrl-G) > use the window align tools, enable the option "Align on the stage" on the bottom, if it is disabled then (align the left edge and align top edge).

    EDIT

  • How to scroll by using the mouse wheel on a parent scroll pane

    Hi guys,.
    Imagine a table. In each cell of the table represents a component of a get. All aspects of ahmed are configured so that the scroll bar is visible only when it is necessary.
    Then, ALL cells contain scroll shutters, but only a few of them actually show a scroll bar.
    The entire table (which is very large) is also in a global scroll pane and is drop-down.

    My problem:
    I want to use the mouse wheel to scroll on the entire table. Because the table contains all its cells do scroll panes, the inner scrollpanes takes very quickly focus and global scrolling stops immediately.
    How can I force the weel mouse seize ONLY on the overall scroll pane? So basically not to transfer events to its internal components?

    I tried to disable the mouse wheel on all aspects of internal scroll:
    xxx.setWheelScrollingEnabled(false);
    ... but it doesn't.
    Any idea?

    So basically not to transfer events to its internal components?

    You must manually transfer the events to the external component to scroll.

    Using the concepts presented in [url http://tips4java.wordpress.com/2009/08/30/global-event-listeners/] Global event listeners, you can do something like:

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    public class ScrollSSCCE extends JPanel
    {
         public ScrollSSCCE()
         {
              setLayout( new BorderLayout() );
    
              Box tables = Box.createVerticalBox();
              final JScrollPane scrollPane = new JScrollPane( tables );
              add( scrollPane );
    
              for (int i = 0; i < 5; i++)
              {
                   JTable table = new JTable(20, 4);
                   JScrollPane sp = new JScrollPane( table );
                   sp.setPreferredSize( new Dimension(300, 200) );
                   sp.setWheelScrollingEnabled( false );
                   tables.add( sp );
              }
    
              long eventMask = AWTEvent.MOUSE_WHEEL_EVENT_MASK;
    
              Toolkit.getDefaultToolkit().addAWTEventListener( new AWTEventListener()
              {
                  public void eventDispatched(AWTEvent e)
                  {
                       Component source = (Component)e.getSource();
    
                      if (source != scrollPane
                        &&  SwingUtilities.isDescendingFrom(source, scrollPane) )
                      {
                           MouseWheelEvent mwe = (MouseWheelEvent)e;
    
                        MouseWheelEvent event = new MouseWheelEvent(
                                  scrollPane,
                                  mwe.getID(),
                                  mwe.getWhen(),
                                  mwe.getModifiers(),
                                  mwe.getX(),
                                  mwe.getY(),
                                  mwe.getXOnScreen(),
                                  mwe.getYOnScreen(),
                                  mwe.getClickCount(),
                                  mwe.isPopupTrigger(),
                                  mwe.getScrollType(),
                                  mwe.getScrollAmount(),
                                  mwe.getWheelRotation());
    
                             scrollPane.dispatchEvent( event );
                      }
                  }
              }, eventMask);
    
         }
    
         private static void createAndShowUI()
         {
              JFrame frame = new JFrame("ScrollSSCCE");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.add( new ScrollSSCCE() );
              frame.setSize(330, 600);
              frame.setLocationRelativeTo( null );
              frame.setVisible( true );
         }
    
         public static void main(String[] args)
         {
              EventQueue.invokeLater(new Runnable()
              {
                   public void run()
                   {
                        createAndShowUI();
                   }
              });
         }
    }
    
  • A scroll pane is loaded dynamically?

    Hallo,

    I added a scroll pane or two via the Component Inspector to my site in flash.

    I know how to add content in the scrolling pane (rename contentpath to the new movie).

    My question: means that scrolling components loading dynamically, IE. they are called only for when you press a button to call this specific page that has the side scrolling and what it means it would save you filesize on your. SWF?

    Thank you!

    all components are related to the export for actionscript (unless cancel you that) which means that they download, whether or not they are used in a swf file.

  • Scroll pane and scroll wheel

    Y at - it a code that will make the scroll pane work with the help of the scroll of the mouse wheel?

    Any help is greatly appreciated.

    Using the scroll wheel may have results mixed in the browser windows, with results different cross-platform. The best of cases, this is where the browser window is large enough to display the entire contents without scroll bars appearing, so when you scroll not, that the browser does not seek to retrieve events for himself. That said, the mousewheel events has not used to work on Macs, so if you try to make it work on a mac in an older Flash player, you can use something like swfaddress, which has inside Javascript code for Macs to see events. With player 10.1, it now seems to work on Mac too, adnd you have nothing to do, the ScrollPane itself listen to events.

Maybe you are looking for