0

我有一个简单的 javafx 应用程序在调整大小时挂起。

应用程序使用 jdk1.7.0_10 编译/构建
操作系统:Windows 8
IDE:NetBeans 7.2.1

当我填充底部表格并通过移动应用程序的右边框开始调整大小时,就会出现问题。有时我需要调整大小一段时间,移动 SplitPanes 的内部边界和外部应用程序边界,直到它崩溃。当该行为空时,即表中没有填充任何内容,那么一切正常 - 没有悬挂,我可以在每个方向调整我想要的大小 - 并且没有任何悬挂。应用程序挂起并以 Java 结果结束:Netbeans 输出窗口中的 255。
会是什么呢?没有日志,异常,什么都没有……这让我发疯,在上面浪费了很多时间:(

这是我的控制器:

public class MyFXMLController implements Initializable {

@FXML
TableView<Person> table;

@FXML
TableColumn<Person, String> firstNameCol;
@FXML
TableColumn<Person, String> lastNameCol;
@FXML
TableColumn<Person, String> carCol;

@Override
public void initialize(URL url, ResourceBundle rb) {
    // TODO

    firstNameCol.setCellValueFactory(new PropertyValueFactory("firstName"));
    lastNameCol.setCellValueFactory(new PropertyValueFactory("lastName"));
    carCol.setCellValueFactory(new PropertyValueFactory("car"));

    Person p1 = new Person();
    p1.setFirstName("A");
    p1.setLastName("B");
    p1.setCar("ferrari");
    ObservableList<Person> teamMembers = FXCollections.observableArrayList(p1);
    table.setItems(teamMembers);
}
}

主要课程是:

public class TestTableView extends Application {

@Override
public void start(Stage primaryStage) {
    Button btn = new Button();
    btn.setText("Say 'Hello World'");
    btn.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            System.out.println("Hello World!");
        }
    });

    AnchorPane page = null;
    try {
        page = (AnchorPane) FXMLLoader.load(TestTableView.class.getResource("/testtableview/myFXML.fxml"));
    } catch (IOException ex) {
        Logger.getLogger(TestTableView.class.getName()).log(Level.SEVERE, null, ex);
    }
    Scene scene = new Scene(page);
    primaryStage.setScene(scene);
    primaryStage.setTitle("my");
    primaryStage.show();
}

/**
 * The main() method is ignored in correctly deployed JavaFX application.
 * main() serves only as fallback in case the application can not be
 * launched through deployment artifacts, e.g., in IDEs with limited FX
 * support. NetBeans ignores main().
 *
 * @param args the command line arguments
 */
public static void main(String[] args) {
    launch(args);

}
}

和使用的 FXML 文件:

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

<?import java.lang.*?>
<?import java.net.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

    <AnchorPane id="AnchorPane" prefHeight="400.0" prefWidth="715.0000999999975" styleClass="mainFxmlClass" xmlns:fx="http://javafx.com/fxml" fx:controller="testtableview.MyFXMLController">
      <children>
        <SplitPane dividerPositions="0.22720894429047145" focusTraversable="true" prefHeight="400.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
          <items>
            <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
              <children>
                <TreeView prefHeight="398.0" prefWidth="159.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
              </children>
            </AnchorPane>
            <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
              <children>
                <SplitPane dividerPositions="0.5" focusTraversable="true" orientation="VERTICAL" prefHeight="398.0" prefWidth="491.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
                  <items>
                    <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0">
                      <children>
                        <TableView id="table" prefHeight="195.0" prefWidth="489.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
                          <columns>
                            <TableColumn prefWidth="75.0" text="Column X" />
                            <TableColumn prefWidth="75.0" text="Column X">
                              <columns>
                                <TableColumn prefWidth="75.0" text="Column X" />
                                <TableColumn prefWidth="75.0" text="Column X" />
                              </columns>
                            </TableColumn>
                            <TableColumn prefWidth="75.0" text="Column X">
                              <columns>
                                <TableColumn prefWidth="75.0" text="Column X" />
                                <TableColumn prefWidth="75.0" text="Column X" />
                              </columns>
                            </TableColumn>
                            <TableColumn prefWidth="75.0" text="Column X" />
                            <TableColumn prefWidth="75.0" text="Column X" />
                          </columns>
                        </TableView>
                      </children>
                    </AnchorPane>
                    <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0">
                      <children>
                        <TableView fx:id="table" prefHeight="195.0" prefWidth="489.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
                          <columns>
                            <TableColumn prefWidth="75.0" text="firstNameCol" fx:id="firstNameCol" />
                            <TableColumn prefWidth="75.0" text="lastNameCol" fx:id="lastNameCol" />
                            <TableColumn prefWidth="75.0" text="carCol" fx:id="carCol" />
                            <TableColumn prefWidth="75.0" text="Column X" />
                            <TableColumn prefWidth="75.0" text="Column X" />
                            <TableColumn prefWidth="75.0" text="Column X" />
                          </columns>
                        </TableView>
                      </children>
                    </AnchorPane>
                  </items>
                </SplitPane>
              </children>
            </AnchorPane>
          </items>
        </SplitPane>
      </children>
      <stylesheets>
        <URL value="@myfxml.css" />
      </stylesheets>
    </AnchorPane>

底层数据类是:

package testtableview;

import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;

public class Person {

    private StringProperty firstName;

    public void setFirstName(String value) {
        firstNameProperty().set(value);
    }

    public String getFirstName() {
        return firstNameProperty().get();
    }

    public StringProperty firstNameProperty() {
        if (firstName == null) {
            firstName = new SimpleStringProperty(this, "firstName");
        }
        return firstName;
    }
    private StringProperty lastName;

    public void setLastName(String value) {
        lastNameProperty().set(value);
    }

    public String getLastName() {
        return lastNameProperty().get();
    }

    public StringProperty lastNameProperty() {
        if (lastName == null) {
            lastName = new SimpleStringProperty(this, "lastName");
        }
        return lastName;
    }

       private StringProperty car;

    public void setCar(String value) {
        carProperty().set(value);
    }

    public String getCar() {
        return carProperty().get();
    }

    public StringProperty carProperty() {
        if (car == null) {
            car = new SimpleStringProperty(this, "car");
        }
        return car;
    }

}
4

1 回答 1

0

但是我在这里看不到任何具体问题。但这可能是您的内存管理问题。尝试使数据类静态作为控制器类中的子类。

于 2013-07-24T14:49:17.913 回答