7 Replies Latest reply: Jul 2, 2011 3:20 AM by 861530 RSS

    Placing label right hand side

    861530
      Am using javafx1.3 and i want to place the label in the right hand side of the scene is it possible??
        • 1. Re: Placing label right hand side
          Narayan
          Hi jbs,
          You can use the bind in label like:
            var lb:Label = Label{
                   layoutX:bind scene.width -  lb.layoutBound.width
                   // your code
          }
          Thanks
          Narayan
          • 2. Re: Placing label right hand side
            DarrylBurke
            Use a layout and set <tt>hpos</tt>.
            import javafx.scene.Scene;
            import javafx.scene.control.Label;
            import javafx.geometry.HPos;
            import javafx.stage.Stage;
            import javafx.scene.layout.HBox;
            
            def label = Label {
                      text: "Right aligned label"
                    };
            def hBox = HBox {
                      width: 500
                      hpos: HPos.RIGHT
                      content: [label]
                    };
            
            Stage {
              scene: Scene {
                content: [hBox]
              }
            }
            db
            • 3. Re: Placing label right hand side
              861530
              Tried but no reaction still the label stays in the constant place on left
              • 4. Re: Placing label right hand side
                DarrylBurke
                What do you mean, tried? All you have to do is run the script I posted and see for yourself that it works.

                db
                • 5. Re: Placing label right hand side
                  861530
                  using netbeans 6.9 i just pasted the code as it appeared with no width so i added the width and height for the stage but it stays on the left which means i tried
                  • 6. Re: Placing label right hand side
                    DarrylBurke
                    The code was written and tested with NetBeans 6.8 / JavaFX plugin version 1.10.3 and worked fine. I've posted a screenshot [url http://i660.photobucket.com/albums/uu323/darrylbu/Screenshots/RightAlignedLabel.png]here

                    db
                    • 7. Re: Placing label right hand side
                      861530
                      Hi Darrl Burke,
                      In javafx 1.3 we have to declare explicitly the layoutinfo in-order to align the label in the right hand side and also sorry for the delay here is the code below
                      package javafxapplication21;
                      
                      import javafx.scene.Scene;
                      import javafx.scene.control.Label;
                      import javafx.geometry.HPos;
                      import javafx.stage.Stage;
                      import javafx.scene.layout.HBox;
                      import javafx.scene.layout.LayoutInfo;
                      
                      def label = Label {
                                text: "Right aligned label"
                              };
                      def hBox = HBox {
                                layoutInfo : LayoutInfo {width: 500}
                                hpos: HPos.RIGHT
                                content: [label]
                              };
                      
                      Stage {
                        scene: Scene {
                          content: [hBox]
                        }
                      }
                      netbeans 6.8 is compatible with javafx 1.2 and i think thats what the difference between the declarations any how thankz for answering my question