Witam!
Oto mój kod:
kontroler:
package Planik ;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.MouseEvent;
import javafx.scene.text.Font;
import javafx.stage.Stage;
/**
*
* @author Kamil
*/
public class PlanKontroler implements Initializable {
@FXML TableView<Tydzien> tabelaPlan;
@FXML TableColumn<Tydzien, String> godzina;
@FXML TableColumn<Tydzien, String> pon;
@FXML TableColumn<Tydzien, String> wto;
@FXML TableColumn<Tydzien, String> sro;
@FXML TableColumn<Tydzien, String> czw;
@FXML TableColumn<Tydzien, String> pr;
@FXML TableColumn<Tydzien, String> sob;
@FXML TableColumn<Tydzien, String> niedz;
private int numer =1;
final ObservableList<Tydzien> data = FXCollections.observableArrayList(
new Tydzien("8","cos","cos","cos","cos","cos","cos","cos"),
new Tydzien("8","cos","cos","cos","cos","cos","cos","cos")
);
@Override
public void initialize(URL location, ResourceBundle resources) {
godzina.setCellValueFactory(new PropertyValueFactory<Tydzien, String>("godzina"));
godzina.setCellValueFactory(new PropertyValueFactory<Tydzien, String>("pon"));
godzina.setCellValueFactory(new PropertyValueFactory<Tydzien, String>("wto"));
godzina.setCellValueFactory(new PropertyValueFactory<Tydzien, String>("sr"));
godzina.setCellValueFactory(new PropertyValueFactory<Tydzien, String>("czw"));
godzina.setCellValueFactory(new PropertyValueFactory<Tydzien, String>("pt"));
godzina.setCellValueFactory(new PropertyValueFactory<Tydzien, String>("sob"));
godzina.setCellValueFactory(new PropertyValueFactory<Tydzien, String>("niedz"));
}
}
Plik FXML:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane id="AnchorPane" prefHeight="663.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1">
<children>
<TableView fx:id="tabelaPlan" layoutY="-1.0" prefHeight="663.0" prefWidth="800.0" tableMenuButtonVisible="true" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columns>
<TableColumn fx:id="godzina" editable="false" prefWidth="100.0" sortable="false" text="Godzina" />
<TableColumn fx:id="pon" prefWidth="100.0" sortable="false" text="Poniedziałek" />
<TableColumn fx:id="wto" prefWidth="100.0" sortable="false" text="Wtorek" />
<TableColumn fx:id="sro" prefWidth="100.0" sortable="false" text="Środa" />
<TableColumn fx:id="czw" prefWidth="100.0" sortable="false" text="Czwartek" />
<TableColumn fx:id="pt" prefWidth="100.0" sortable="false" text="Piątek" />
<TableColumn fx:id="sob" prefWidth="100.0" sortable="false" text="Sobota" />
<TableColumn fx:id="niedz" prefWidth="100.0" sortable="false" text="Niedziala" />
</columns>
</TableView>
</children>
</AnchorPane>
oraz klasa tydzien:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package planik;
import javafx.beans.property.SimpleStringProperty;
/**
*
* @author Kamil
*/
public class Tydzien {
private final SimpleStringProperty pon, wto,sro,czw,pt,sob,niedz,godzina;
public Tydzien(String godzina, String pon, String wto, String sro, String czw, String pt,String sob,String niedz) {
this.godzina = new SimpleStringProperty(godzina);
this.pon = new SimpleStringProperty(pon);
this.wto = new SimpleStringProperty(wto);
this.sro = new SimpleStringProperty(sro);
this.czw = new SimpleStringProperty(czw);
this.pt = new SimpleStringProperty(pt);
this.sob = new SimpleStringProperty(sob);
this.niedz = new SimpleStringProperty(niedz);
}
public String getPon() {
return pon.get();
}
public void setPon(String v){
pon.set(v);
}
public SimpleStringProperty getWto() {
return wto;
}
public void setWto(String v){
wto.set(v);
}
public SimpleStringProperty getSro() {
return sro;
}
public void setSro(String v){
sro.set(v);
}
public SimpleStringProperty getCzw() {
return czw;
}
public void setCzw(String v){
czw.set(v);
}
public SimpleStringProperty getPt() {
return pt;
}
public void setPt(String v){
pt.set(v);
}
public SimpleStringProperty getSob() {
return sob;
}
public void setSob(String v){
sob.set(v);
}
public SimpleStringProperty getNiedz() {
return niedz;
}
public void setNiedz(String v){
niedz.set(v);
}
public SimpleStringProperty getGodzina() {
return godzina;
}
public void setGodzina(String v){
godzina.set(v);
}
}
dlaczego gdy w tej czesci kodu dodaje do tabeli Stringi to nic mi nie dodaje ?
final ObservableList<Tydzien> data = FXCollections.observableArrayList(
new Tydzien("8","cos","cos","cos","cos","cos","cos","cos"),
new Tydzien("8","cos","cos","cos","cos","cos","cos","cos")
);
dziekuję za wszelkie porady!