Tried adding comboBox content

This commit is contained in:
Marco Kühn 2022-01-26 15:04:32 +01:00
parent 596343fe47
commit 91daf95990
3 changed files with 28 additions and 10 deletions

View File

@ -1,16 +1,24 @@
package main; package main;
import com.jfoenix.controls.*; import com.jfoenix.controls.*;
import helper.HttpRequestException;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.Node; import javafx.scene.Node;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import javafx.stage.Modality; import javafx.stage.Modality;
import javafx.stage.Stage; import javafx.stage.Stage;
import res.DataController;
import res.User;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects; import java.util.Objects;
public class OptionController { public class OptionController {
@ -27,9 +35,26 @@ public class OptionController {
public Label labelError; public Label labelError;
@FXML @FXML
public JFXComboBox<String> userCmb; public JFXComboBox<String> userCmb;
@FXML
public GridPane mainGrid;
@FXML @FXML
public void initialize(){ public void initialize(){
DataController dataController = new DataController();
List<User> users;
try{
users = dataController.getAllUser();
} catch (HttpRequestException e){
users = new ArrayList<>();
}
ObservableList<String> observableUserList = FXCollections.observableArrayList();
for (User user: users) {
observableUserList.add(user.getLogin());
}
JFXComboBox comboBox = new JFXComboBox(observableUserList);
comboBox.getStyleClass().add("comboBox");
mainGrid.add(comboBox, 2,2);
} }

View File

@ -3,12 +3,12 @@
<?import javafx.scene.control.*?> <?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.*?>
<?import com.jfoenix.controls.*?> <?import com.jfoenix.controls.*?>
<?import javafx.collections.FXCollections?>
<GridPane xmlns="http://javafx.com/javafx" <GridPane xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml" xmlns:fx="http://javafx.com/fxml"
fx:controller="main.OptionController" fx:controller="main.OptionController"
prefHeight="400.0" prefWidth="600.0"> prefHeight="400.0" prefWidth="600.0"
fx:id="mainGrid">
<columnConstraints> <columnConstraints>
<ColumnConstraints minWidth="100"/> <ColumnConstraints minWidth="100"/>
@ -33,13 +33,6 @@
<Label styleClass="mainLabel" GridPane.columnIndex="2" GridPane.halignment="CENTER" >Einstellungen</Label> <Label styleClass="mainLabel" GridPane.columnIndex="2" GridPane.halignment="CENTER" >Einstellungen</Label>
<Label GridPane.columnIndex="1" GridPane.rowIndex="2" GridPane.halignment="CENTER">User:</Label> <Label GridPane.columnIndex="1" GridPane.rowIndex="2" GridPane.halignment="CENTER">User:</Label>
<JFXComboBox styleClass="comboBox" fx:id="userCmb" GridPane.columnIndex="2" GridPane.rowIndex="2">
<items>
<FXCollections fx:factory="observableArrayList">
</FXCollections>
</items>
</JFXComboBox>
<JFXButton styleClass="userBtn" fx:id="updateUserBtn" GridPane.columnIndex="1" GridPane.columnSpan="3" <JFXButton styleClass="userBtn" fx:id="updateUserBtn" GridPane.columnIndex="1" GridPane.columnSpan="3"
GridPane.rowIndex="4" GridPane.halignment="CENTER" onAction="#onUpdateBtnClick">User bearbeiten</JFXButton> GridPane.rowIndex="4" GridPane.halignment="CENTER" onAction="#onUpdateBtnClick">User bearbeiten</JFXButton>

View File

@ -138,7 +138,7 @@ public class DataController {
* User * * User *
********/ ********/
public List<User> getUser() throws HttpRequestException { public List<User> getAllUser() throws HttpRequestException {
String userJSON = sendBasicHttpRequest( String userJSON = sendBasicHttpRequest(
ALL_USER_ENDPOINT, ALL_USER_ENDPOINT,
"", "",