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

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 provide Horizontal tool bar at the bottom of the form?

    Hi Friends,
    I have form with 8 tab pages. I created a horizontal toolbar canvas with some navigational buttons. I want to put the horizontal toolbar at the bottom of the form which is common to all of my tab pages of that particular form.
    How can I do that?
    Thank You.
    Gopinath Kona

    Iam not very sure...but let me give it a try. As far as my knowledge goes, horizontal tool bar can be placed only the top side of the form.
    For your requirement, u can probably try out placing the buttons on a stacked canvas and display the same for every tab page in your form...
    HTH

  • How can I get a scroll bar at the bottom of the page so I can see the right side of the page when I am using two windows?

    With two or three pages open, I have scroll bars that allow me to see the right side of the other pages, but not on the Firefox page.

    Thank you for the reply, Fred, but when I went to my saved screenshot, I realized that the shortcut on my desktop had opened in IE, not Firefox. There is no scroll bar and the directional arrows do not work. My daughter has been playing with my laptop again. When I set up the same conditions with Firefox, there is no scroll bar, but the arrows function properly, so I can read to the right edge of the page. Now to find someone who knows IE11. Thanks again, for your reply.

  • 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

  • When I view the summary of content on my iphone5, the status bar at the bottom to the iTunes window shows I have 3.90 Gb's of "other".  What is that about and how can I free up that space?

    when I view the summary of content on my iphone5, the status bar at the bottom to the iTunes window shows I have 3.90 Gb's of "other".  What is that about and how can I free up that space? 

    I simply restored my iPhone from most recent  iCloud  backup.  Poof. Good to go!!!

  • How can I customize my status bar to change the color?

    Hello:
    How can I customize my status bar to change the color?
    Thanks

    On which phone model? Either way, modifying the notification bar text color usually isn't something you can do with a standard stock phone.

  • How do I keep my status bar at the top and not moving from side to side and bottom of phone

    how do I keep my status bar at the top of my phone? I let my grandsn play a game on my phone and after he gave it back I noticed my status bar would move from the top to the side or bottom etc

    Reset, hold both home and power buttons until the iPhone begins to restart itself, ignore the slide to power off slider. Let the iPhone restart itself. Usually takes about 10 seconds of holding both buttons.
    Probably do not need this, but Portrait Lock can be set by, pressing home button twice quickly, slide bottom row of icons to the right one time, tap the Portrait Lock icon.

  • Status Bar at the bottom of applet

    Hi,
    How can I get rid of Status bar at the bottom of an applet?
    I dont' wana see word "Java Applet Started". I have called
    JFrame.setDefaultLookAndFeelDecorated(true);
    Everything is fine, but the unwanted status bar at the bottom.
    Any help is greatly appreciated.
    Regards

    Howdy.
    Not sure what you are trying to achieve here. The appletviewer sounds like it is working as designed. If you are writing an applet then I'd assume that you intend for it to be accessed via a web browser. The appletviewer is simply a test mechanism.
    However, your concern about the way in which the appletviewer presents itself leads me to think that you are intending all users to run your app. using the appletviewer. If this is the case then why not just create the frame directly? This code does just that.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class SimpleJFrame extends JFrame {
         public static void main(String[] a){
              SimpleJFrame cleanFrame = new SimpleJFrame();
         SimpleJFrame() {
              // user interface
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              setTitle("SimpleJFrame");
              Container cp = getContentPane();
              cp.setLayout(new FlowLayout());
              cp.add(new JButton("Press"));
              cp.add(new JTextField(8));
              pack();
              show();
    }regards
    sjl

  • Status bar at the bottom of the screen stops working. need to fix it.

    When I upgrade Thunderbird there is a status bar at the bottom of the page that shows what account is being logged into and what the status is of the login process. (this is real time) What happens after a while is that the status no longer works and all I see is Unread: X and Total: X. I really would like the feature to work as it lets me know when I have connectivity issues. Either there is a bug in the software or some add on is messing thunderbird up. I have tried to disable all add ons and other features to no avail, so I think this is more of a bug. How to I fix the problem?

    The add on Adblocker Plus is known to cause this problem. Are you sure you do not have this add on active? After disabling the add on restart Thunderbird and then check the status bar operation.

  • HT1386 When I try to sync my iphone with itunes, it tells me in a warning that I don't have enough memory and yet the status bar on the bottom says I do and I know that I have enough memory.What's as

    When I try to sync my iphone with itunes, it tells me a warning that I don't have enough memory and yet the status bar at the bottom says that I do and I know that I have enough memory. What's the problem? It happens with the ipods and ipad as well!!!

    The new iTunes has a somewhat different look from the previous version.  You can get the old look back if you prefer it by doing View > Show Sidebar in iTunes.  Or you can adapt to the new look.

  • 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.

  • Can iCal display a month bar at the bottom?

    Is it possible to make iCal display the useful bar at the bottom  - so you can click straight into any month - the way it displays on the iPad and also the iCloud website? If so, how do I do this?

    Not that I have found.
    If using the <today> link or swiping through the months while in Month view takes to long you can set the iCal page to show 'Year' then double click the month you want.
    S.

  • How to display table range navigation bar at the bottom of the tr table i

    Hello,
    While I am using trinidad, I have to face a critical issue. Can I display table range navigation bar at the bottom of the <tr table> in Trinidad? and remove the range dropdown list, only show the "previous" and "next" link? The project is critical on the UI, this problem is very small but has to be fixed? Does anyone have any ideas&#65311;

    Difficult to do?  No.
    <ul id="bottom-nav"><li><a hef="whatever.php">whatever</a></li><li class="last"><a hef="whatever2.php">whatever2</a></li></ul>
    With this CSS -
    ul#bottom-nav {
         list-style-type:none;
         overflow:hidden;
         width:70%;
         margin:0 auto;
    ul#bottom-nav li {
         float:left;
         padding-right:10px;
         border-right:1px solid #FFF;
    ul#bottom-nav li.last {
         border:none;
    ul#bottom-nav a {
         /* your styles here */

  • How can i pin a text box to the bottom of a VBOX

    Hi,
    Thank you in advance for your time, the question is how do i pin a text box to the bottom of a VBox, i dont know what code to add kindly help me out. The code i have with me is
    VBox {
    translateX: 10
    translateY: 10
    spacing: 20
    content: [
    Label {
    text: "TextBox:"
    TextBox {
    layoutInfo: LayoutInfo { minWidth: 100 width: 150 maxWidth: 200 }
    ] //contents
    //VBox
    now the text box has to go to the bottom of the VBox even if the VBox has other objects or if its resized.
    Regards,
    Kibu

    Vbox, acts much like a linear layout like in other languages.
    Just keep your declared textbox at the bottom of your content (content :[] ), then the text box will continue to get pushed further down your view, as you add other controls to your content.
    layoutX and layoutY will just increase your spacing from the previous declared control in that content.

Maybe you are looking for