我正在使用JavaFX为我的父母用Java编写财务控制类型的应用程序,但是我遇到了GUI的问题。我搜索了谷歌和代码中的问题,但我似乎找不到任何错误。
这是我用作指南的链接:http://docs.oracle.com/javafx/2/ui_controls/table-view.htm
我开始使用TableView使用Calender。顺便问一下,有没有其他方法可以用JavaFX制作日历?
无论如何,这是代码:
包财务;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.stage.Stage;
import java.text.DateFormatSymbols;
import java.util.Calendar;
import java.util.GregorianCalendar;
public class Main extends Application {
Calendar calendar = new GregorianCalendar();
private TableView<Week> table = new TableView<Week>();
final ObservableList<Week> data = FXCollections.observableArrayList(
new Week("1", "2", "3", "4", "5", "6", "7")
);
@Override
public void start(Stage primaryStage) throws Exception {
Scene scene = new Scene(new Group());
primaryStage.setTitle("Finance Control");
primaryStage.setWidth(1000);
primaryStage.setHeight(700);
Label month = new Label(getMonthForInt(calendar.get(Calendar.MONTH)));
month.setFont(new Font("Arial", 30));
table.setEditable(false);
table.setPrefHeight(500);
table.setPrefWidth(882);
TableColumn sun = new TableColumn("Sunday");
TableColumn mon = new TableColumn("Monday");
TableColumn tue = new TableColumn("Tuesday");
TableColumn wed = new TableColumn("Wednesday");
TableColumn thu = new TableColumn("Thursday");
TableColumn fri = new TableColumn("Friday");
TableColumn sat = new TableColumn("Saturday");
sun.setCellValueFactory(
new PropertyValueFactory<Week, String>("a")
);
mon.setCellValueFactory(
new PropertyValueFactory<Week, String>("b")
);
tue.setCellValueFactory(
new PropertyValueFactory<Week, String>("c")
);
wed.setCellValueFactory(
new PropertyValueFactory<Week, String>("d")
);
thu.setCellValueFactory(
new PropertyValueFactory<Week, String>("e")
);
fri.setCellValueFactory(
new PropertyValueFactory<Week, String>("f")
);
sat.setCellValueFactory(
new PropertyValueFactory<Week, String>("g")
);
TableColumn[] days = {sun, mon, tue, wed, thu, fri, sat};
for (TableColumn day: days) {
day.setPrefWidth(table.getPrefWidth()/7);
}
table.setItems(data);
table.getColumns().addAll(sun, mon, tue, wed, thu, fri, sat);
final VBox vbox = new VBox();
vbox.setSpacing(5);
vbox.setPadding(new Insets(10, 0, 0, 10));
vbox.setAlignment(Pos.CENTER);
vbox.getChildren().addAll(month, table);
((Group) scene.getRoot()).getChildren().addAll(vbox);
primaryStage.setScene(scene);
primaryStage.show();
}
String getMonthForInt(int num) {
String month = "wrong";
DateFormatSymbols dfs = new DateFormatSymbols();
String[] months = dfs.getMonths();
if (num >= 0 && num <= 11 ) {
month = months[num];
}
return month;
}
public static void main(String[] args) {
launch(args);
}
public static class Week {
String a;
String b;
String c;
String d;
String e;
String f;
String g;
public Week(String a, String b, String c, String d, String e, String f, String g) {
this.a = a;
this.b = b;
this.c = c;
this.d = d;
this.e = e;
this.f = f;
this.g = g;
}
}
}
当我运行它时会发生这种情况。我希望它填充我给Week对象的构造函数的值,但它不是 - 它只显示空单元格。
如果重要的话,我正在使用IDEA IDE ...如果对此或任何评论有任何帮助,我将不胜感激。我可能会在某些时候使用scenebuilder,但我想在进入GUI构建器之前先了解一下实际的代码。
答案 0 :(得分:0)