2014-01-20 2 views
0

JavaFX를 사용하여 부모님을위한 금융 제어 유형 응용 프로그램에서 작업하고 있지만 GUI에 문제가 있습니다. Google과 문제 코드를 검색했지만 잘못된 것을 찾지 못했습니다. 내가있는 TableView를 사용하여 캘린더로 떨어져 시작하고 http://docs.oracle.com/javafx/2/ui_controls/table-view.htmJavaFX TableView 데이터가 CellValueFactory에 표시되지 않습니다.

:

내가 가이드 라인으로 사용하고 링크입니다. 그런데 JavaFX로 캘린더를 만들 수있는 다른 방법이 있습니까?

어쨌든 코드는 다음과 같습니다.

package Finance;

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 객체의 Constructor에 부여한 값으로 채울 것으로 예상되지만, 빈 셀만 표시됩니다. 그 중요한 경우 내가 IDEA의 IDE를 사용하고

http://i.imgur.com/ZrhPIDe.png

... 나는이 나 의견에 어떤 도움을 감사하게 될 거라고. 아마 어느 시점에서 scenebuilder를 사용할 것이지만, GUI 빌더로 가기 전에 실제 코드에 대한 느낌을 얻고 싶습니다.

답변

0

아, 그걸 해결했습니다. PropertyValueFactory 클래스는 week 클래스의 메소드를 사용하여 값을 가져옵니다. 모든 필드에 대해 일부 getter를 추가하기 만하면됩니다.

+0

당신이 우리에게 어떻게 보여 주면 좋았을 것입니다. – aero

관련 문제