Oberflächen
  Vorlesungen     Download     DBS     Sprachen     File Formats     Impressum     Datenschutz  
C#- GUI-Programme mit Quellcode
Java-Programme mit Quellcode
C#
WPF
HTML
Java FX
Java (Swing)
Winforms
Visual Studio (MFC)
ArcView
QGis
ArcView .net
IDW
Allgemein:
Startseite
Vorlesungen
Labore
Sinnvolle Programme
Lineare Regression
GUI-Entwurfsarbeit
Single-Format
Design Pattern-Termine
Observer1
Bsp2
Json-Array
Json-Dialogelemente
Webtechnologien

TableView

TabView

Beschreibung Download
Dialogfenster mit einem TabView UIBspTabView01.java
UIBspTabView01.png

tableview = new TableView() ;
private ObservableList<Student> listeStd = FXCollections.observableArrayList();

listeStd.addAll(
new Student("Andrea","Meier",12345,1.3),
new Student("Ute","Hein",12545,4.0),
new Student("Manfred","Tischler",12349,5.0),
new Student("Uta","Hein",322545,4.0),
new Student("Anton","Epple",12545,2.7)
);



tableview.setItems(listeStd);
//listview.setPlaceholder(new Label("Bitte etwas auswaehlen"));
tableview.setStyle("-fx-font: 22px \"Serif\";");
tableview.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);

TableColumn<Student, String> colFirstname = new TableColumn<Student, String>("Firstname");
colFirstname.setMinWidth(200); // Mindestbreite setzen
colFirstname.setCellValueFactory( new PropertyValueFactory<Student, String>("firstname"));

// javafx.scene.control.cell.PropertyValueFactory<S,T>
tableview.getColumns().addAll(colFirstname, colLastname,colMnr, colNote);

Abfrage:
ObservableList<Student> selectedItems = tableview.getSelectionModel().getSelectedItems();
double summeNoten=0.0;
for (Student std : selectedItems) {
summeNoten+=std.getNote();
sb.append( std);
sb.append(" , ");
}
double dNote = summeNoten/selectedItems .size();
Dialogfenster mit einem TabView
Neu:
- Eintragen von weiteren Elementen
- FactoryCell
UIBspTabView02.java
UIBspTabView02.png
UIBspTabView02b.png

FactoryCell
class NoteCell extends TableCell<Student,Double> {

@Override
protected void updateItem(Double item, boolean empty) {
super.updateItem(item, empty);
if (item!=null && !empty) {
setText(item.toString());
if (item<3.0)
setTextFill(Color.GREEN);
else if (item<5.0)
setTextFill(Color.BLUE);
else
setTextFill(Color.RED);
}
else {
setText("--");
setTextFill(Color.BLACK);
}
}
} // class NoteCell

// callback: import javafx.util.callback;
colNote.setCellFactory(new Callback<TableColumn<Student,Double>,TableCell<Student,Double>>() {
@Override
public TableCell <Student,Double> call(TableColumn<Student,Double> param) {
return new NoteCell();
}
});

Items insert:
private void insert() {
listeStd.addAll(
new Student("Ute","Abba",12545,4.0),
new Student("Antonia","Epple",12545,2.7)
);
}
Dialogfenster mit einem TabView

Neu:
Sortieren
UIBspTabView03.java
UIBspTabView03.png

import javafx.collections.transformation.SortedList;
import java.util.*; /// Comparator

public class UIBspTableView03 extends Application {

private TableView tableview = new TableView() ;
private ObservableList<Student> listeStd = FXCollections.observableArrayList();
private SortedList<Student> listeSortedStd = null;

// Wichtig: eine interne Compare-Methode funktioniert nicht
Comparator<Student> stdComparator = new Comparator<Student>() {
public int compare(Student std1, Student std2) {
int result = std1.getLastname().compareTo(std2.getLastname());
System.out.println(std1.getLastname()+" "+std2.getLastname()+" res: "+result);
if (result==0) {
result = std1.getFirstname().compareTo(std2.getFirstname());
}
return result;
}
};

@Override
public void start(Stage stage) {
...
listeSortedStd = new SortedList<>(listeStd,stdComparator );
tableview.setItems(listeSortedStd);
...
Scene scene= new Scene(root, 660, 700);
stage.setTitle("UIBspListView03");
stage.setScene(scene);
stage.show();
}
Dialogfenster mit einem TabView

Neu:
- Sortieren
- Filter
UIBspTabView04.java
UIBspTabView04.png

import javafx.collections.transformation.FilteredList;
import javafx.collections.transformation.SortedList;

private TableView tableview = new TableView() ;
private ObservableList<Student> listeStd = FXCollections.observableArrayList();
private SortedList<Student> listeSortedStd = null;



Comparator<Student> stdComparator = new Comparator<Student>() {
public int compare(Student std1, Student std2) {
int result = std1.getLastname().compareTo(std2.getLastname());
System.out.println(std1.getLastname()+" "+std2.getLastname()+" res: "+result);
if (result==0) {
result = std1.getFirstname().compareTo(std2.getFirstname());
}
return result;
}
};

FilteredList<Student> filteredList = new FilteredList<>(listeStd, p -> true);
tFilter.textProperty().addListener((observable, oldValue, newValue) -> {
filteredList.setPredicate(std -> {
// If filter text is empty, display all persons.
if (newValue == null || newValue.isEmpty()) {
return true;
}

// Compare first name and last name of every person with filter text.
String lowerCaseFilter = newValue.toLowerCase();

if (std.getLastname().toLowerCase().contains(lowerCaseFilter)) {
return true;
} else if (std.getFirstname().toLowerCase().contains(lowerCaseFilter)) {
return true;
}
return false; // Does not match.
});
});



listeSortedStd = new SortedList<>(filteredList,stdComparator );
tableview.setItems(listeSortedStd);
Dialogfenster mit einem TabView

Neu:
- mit Editor
UIBspTabView05.java
UIBspTabView05.png
UIBspTabView05b.png

tableview.setOnMouseClicked(e-> tableviewOnClick(e));

Event:
private void tableviewOnClick(MouseEvent e) {
// MIDDLE SECONDARY
if (e.getButton()==MouseButton.PRIMARY && e.getClickCount()==2) {
editSeletedItem();
}
}



private void editSeletedItem() {
int index = tableview.getSelectionModel().getSelectedIndex();
if (index>=0 && index<listeStd.size()) {
// Student std = listeStd.get(index); // geht niocht durch Filter + sortieren
Student std = (Student) tableview.getSelectionModel().getSelectedItem();
// Dialog zum Ändern
EditStage editstage = new EditStage(stage, std);
editstage.showAndWait();
if (editstage.retcode) {
for (int i=0; i<listeStd .size(); i++) {
if (std==listeStd.get(i)) {
System.out.println("i: "+i);
listeStd.set(i,std);
}
}
}
}
else {
Basis.errorBox("Bitte einen Eintrag selektieren","Hinweis");
}
}

editstage



TabPane
TabPane-Snippet