1

I have a TitledPane with ListView inside, and after I collapse the titledPane and expand it, the list is no longer visible, but it's still somewhere. It reappears if I resize the titledPane (by resizing app window). I need the list reappear immediately and also, ultimately this titledPane will have a fixed size with no scaling/growth, so even resizing will not work.

How can I make the list reappear immidiately after expanding the titledPane?

fxml:

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>

<AnchorPane maxHeight="560.0" maxWidth="1000.0" xmlns="http://javafx.com/javafx/8"       xmlns:fx="http://javafx.com/fxml/1"     fx:controller="com.humandevice.drive.fx.controller.MainWindowController">
<children>
  <GridPane layoutX="-159.0" layoutY="-131.0" prefHeight="560.0" prefWidth="1000.0"     AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"     AnchorPane.topAnchor="0.0">
    <columnConstraints>
      <ColumnConstraints hgrow="SOMETIMES" maxWidth="-Infinity" minWidth="201.0"     prefWidth="201.0" />
        <ColumnConstraints hgrow="SOMETIMES" maxWidth="-Infinity" minWidth="-Infinity" prefWidth="3.0" />
      <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
    </columnConstraints>
    <rowConstraints>
        <RowConstraints maxHeight="-Infinity" minHeight="-Infinity" prefHeight="30.0" vgrow="SOMETIMES" />
        <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
      </rowConstraints>
       <children>
          <HBox alignment="CENTER" spacing="50.0" style="-fx-background-color: GREY;"   GridPane.columnIndex="2">
            <children>
               <Button fx:id="goBack" disable="true" mnemonicParsing="false"   onAction="#previousScreen" text="%buttons.back" />
              <Button mnemonicParsing="false" onAction="#openSettingsWindow"   text="%buttons.settings" />
              <Button fx:id="setPublicScreen" mnemonicParsing="false" text="Public" />
              <Button fx:id="setWelcomeScreen" mnemonicParsing="false" text="Welcome" />
              <Button fx:id="logoutButton" mnemonicParsing="false" onAction="#logout"   text="Logout" />
           </children>
           <padding>
              <Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
           </padding>
        </HBox>
        <GridPane fx:id="contentPane" GridPane.columnIndex="2" GridPane.rowIndex="1">
          <columnConstraints>
            <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
          </columnConstraints>
          <rowConstraints>
            <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
          </rowConstraints>
        </GridPane>
        <Separator orientation="VERTICAL" prefHeight="200.0" GridPane.columnIndex="1" GridPane.rowIndex="1" GridPane.rowSpan="2147483647" />
        <VBox alignment="TOP_CENTER" GridPane.rowSpan="2147483647">
           <children>
              <TitledPane animated="false" text="%labels.mypis">
                <content>
                  <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
                       <children>
                          <ListView fx:id="userPisListView" layoutY="-47.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
                       </children>
                    </AnchorPane>
                </content>
                 <VBox.margin>
                    <Insets />
                 </VBox.margin>
              </TitledPane>
              <TitledPane animated="false" text="placeholder">
                <content>
                  <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
                </content>
                 <VBox.margin>
                    <Insets />
                 </VBox.margin>
              </TitledPane>
           </children>
        </VBox>
       </children>
    </GridPane>
  </children>
</AnchorPane>

controller:

package com.humandevice.drive.fx.controller;

//imports

public class MainWindowController implements Initializable {

@FXML
public static GridPane contentPane, previousScreen = Main.welcomeScreen;
@FXML
public static Button goBack, setWelcomeScreen, setPublicScreen,
        logoutButton;
@FXML
ListView<String> userPisListView;

@Override
public void initialize(URL url, ResourceBundle res) {
    listUserPis();
    FXMLLoader loader = new FXMLLoader();
    GridPane content = new GridPane();
    if (Main.lang.equals("pl"))
        loader.setResources(ResourceBundle.getBundle(
                "com.humandevice.drive.fx.bundles.messages", new Locale(
                        "pl", "PL")));
    else
        loader.setResources(ResourceBundle.getBundle(
                "com.humandevice.drive.fx.bundles.messages", new Locale(
                        "en", "EN")));
    try {
        content = (GridPane) loader.load(Main.class.getResource(
                "/com/humandevice/drive/fx/view/WelcomeView.fxml")
                .openStream());
    } catch (IOException e) {
        e.printStackTrace();
    }
    content.setAlignment(Pos.TOP_RIGHT);
    contentPane.add(content, 0, 0);
    setWelcomeScreen.addEventHandler(ActionEvent.ACTION,
            new ContentChangeHandler());
    setPublicScreen.addEventHandler(ActionEvent.ACTION,
            new ContentChangeHandler());

    userPisListView.getSelectionModel().selectedItemProperty()
            .addListener(new ChangeListener<String>() {
                @Override
                public void changed(
                        ObservableValue<? extends String> observable,
                        String oldValue, String newValue) {
                    updateActivePi();
                    changeActivePiScreen();
                }
            });
}

/**
 * TODO Zaladowanie aktywnego Pi na MyPiView
 */
protected void changeActivePiScreen() {
}

/**
 * TODO zmiana aktywnego PI w Main na podstawie nazwy z userPis
 */
protected void updateActivePi() {

}

public void listUserPis() {
    ObservableList<String> piNames = FXCollections.observableArrayList();
    for (PI pi : Main.userPis) {
        piNames.add(pi.getDeviceName());
    }
    userPisListView.setItems(piNames);
}

@FXML
public static void openSettingsWindow() {
    Stage settingsStage = new Stage();
    settingsStage.setTitle("Settings");
    FXMLLoader loader = new FXMLLoader();
    loader.setLocation(Main.class
            .getResource("/com/humandevice/drive/fx/view/SettingsView.fxml"));
    if (Main.lang.equals("pl"))
        loader.setResources(ResourceBundle.getBundle(
                "com.humandevice.drive.fx.bundles.messages", new Locale(
                        "pl", "PL")));
    else
        loader.setResources(ResourceBundle.getBundle(
                "com.humandevice.drive.fx.bundles.messages", new Locale(
                        "en", "EN")));
    GridPane root = new GridPane();
    try {
        root = (GridPane) loader.load();
    } catch (IOException e) {
        e.printStackTrace();
    }
    Scene settingsScene = new Scene(root);
    settingsStage.setScene(settingsScene);
    settingsStage.show();
}

@FXML
public static void previousScreen() {
    System.out.println("Wracam na poprzedni ekran");
    MainWindowController.contentPane.getChildren().set(0, previousScreen);
    goBack.setDisable(true);
}

@FXML
public void logout() {
    try {
        Main.logout();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

}

Structure:

enter image description here

This is what it looks like. Not working listview is in top left corner.

enter image description here

Asalas77
  • 612
  • 4
  • 15
  • 26
  • If you have a proper layout it must work. It seems something wrong with the layout, edit your question and put your code here. – Lalith J. Dec 18 '14 at 12:19
  • I just checked , Layout is fine, Listview is appearing with the TitledPane expanding as expected. Seems you are alerting the listview in control class. I can give you an idea if i see the control class – Lalith J. Dec 18 '14 at 12:42
  • @LalithJayasinghe added controller code – Asalas77 Dec 18 '14 at 12:48
  • possible duplicate of [javafx 8 compatibility issues - FXML static fields](http://stackoverflow.com/questions/23105433/javafx-8-compatibility-issues-fxml-static-fields) – James_D Dec 18 '14 at 13:17
  • Why is everything `static`? – James_D Dec 18 '14 at 13:17
  • yes I just checked , It causing by the static modifier used with the listview . make it like this private ListView userPisListView; remove static from your methods also – Lalith J. Dec 18 '14 at 13:19
  • @James_D it is static because i need to use those fields outside the controller – Asalas77 Dec 18 '14 at 15:50
  • That has nothing to do with `static`. `static` fields and members are just properties of the class, not of the instances of the class. – James_D Dec 18 '14 at 16:21

1 Answers1

0

It causing by the static modifier you used with the listview . static variables work with FML in JavaFX 2.2. It doesn't work in JavaFX 8. make it like this,

private ListView<String> userPisListView;

Also remove static from your methods for avoiding compatibility issues.

Lalith J.
  • 1,391
  • 4
  • 16
  • 27
  • `static` variables may be injected by the FXML loader in JavaFX 2.2, but it doesn't mean they "work" (as can be seen in this example). It makes absolutely no sense whatsoever to make these variables `static`; they are clearly properties of the controller instance, not the controller class. – James_D Dec 18 '14 at 13:31
  • 1
    I removed the static modifier but it's still not working – Asalas77 Jan 12 '15 at 10:51