我有一个简单的javafx应用程序,在调整大小时会挂起。
使用jdk1.7.0_10编译/构建应用程序
操作系统:Windows 8
IDE:NetBeans 7.2.1
当我填充底部表并通过移动应用程序的右边框开始调整大小时,会出现问题。有时我需要调整一段时间,调整SplitPanes和外部应用程序边框的内部边界直到它崩溃。当行为空时,表中没有任何内容,那么一切正常 - 没有挂起,我可以随心所欲地调整每个方向 - 没有任何东西挂起。 应用程序在Netbeans输出窗口中以Java Result: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;
}
}
答案 0 :(得分:0)
但是我在这里看不到任何具体问题。但它可能是你的记忆管理问题。尝试将数据类静态化为控制器类中的子类。