Hide checkbox in java with Scenebuilder - scenebuilder

I am working with eclipse jee photon and scenebuilder.
What I am trying to do:
I have a choicebox with two labels:
ObservableList labelList = FXCollections.observableArrayList("examlpe01", "example02");
If example01 is chosen, the checkbox should be visible but disabled. If example02 is chosed the checkbox should be visible and it should be possible to check it.
Here is my code:
public class newUser{
ObservableList <String> labelList = FXCollections.observableArrayList("example01", "example02");
#FXML
private TextField name;
#FXML
private TextField lastName;
#FXML
private Button saveUser;
#FXML
private CheckBox adminRights;
#FXML
private TextField emailAdress;
#FXML
private TextField password;
#FXML
private Button userSpeichern;
#FXML
private MenuButton userDropDown;
#FXML
private MenuItem adminpage;
#FXML
private MenuItem example01;
#FXML
private MenuItem example02;
#FXML
private MenuItem logout;
#FXML
private ChoiceBox label;
#FXML
private void initialize() {
label.setItems(labelList);
label.setValue("mm");
}
#FXML
void logout(ActionEvent event) throws IOException {
Parent Login = FXMLLoader.load(getClass().getClassLoader().getResource("fxml/Login.fxml"));
Scene Login_scene = new Scene(Login);
Stage app_stage = (Stage) userDropDown.getScene().getWindow();
app_stage.setScene(Login_scene);
app_stage.show();
}
DbHelper db = new DbHelper();
private void showCheckbox() {
if (label.equals("example02")) {
}
}
#FXML
void saveUserData(ActionEvent event) {
}

Use this:
#FXML
ChoiceBox choiceBox;
#FXML
CheckBox checkBox;
#FXML
private void choiceBoxOnClicked() {
if (choiceBox.getValue().equals("example01")) {
checkBox.setDisable(true);
} else if (choiceBox.getValue().equals("example02")) {
checkBox.setDisable(false);
}
}
So this should work.

Related

JavaFX BorderPane

i'm trying to set on top of a borderpane an fxml hbox, the borderpane is inside another borderpane that contains all.
The containers are in this form:
Stage-> PincipalBorderPane -> Vbox(Center of MainMenuBorderPane)-> ContentBorderPane(in bottom of Vbox).
Also in the left of my PrincipalBorderPane, I have a sidebar menu that contains buttons, I want to set on the top of ContentBorderPane an fxml document that will be like an small menu to show buttons that would set on the bottom of ContentMenu different panes. The problem is that I don't know how to set an fxml to a borderpane that is inside another borderpane.
public class MenuContentController implements Initializable {
private boolean flag = true;
private boolean flagsc = true;
#FXML
private JFXButton Minbtn;
#FXML
private JFXButton Maxbtn;
#FXML
private JFXButton Closebtn;
#FXML
private JFXButton Sidebarbtn;
#FXML
private JFXTextField Searchtxt;
#FXML
private JFXButton Ingressbtn;
#FXML
private JFXButton Egressbtn;
#FXML
private JFXButton Statusbtn;
#FXML
private BorderPane ContentTools;
#FXML
private void open_sidebar(ActionEvent event) throws IOException {
BorderPane border_pane = (BorderPane) ((Node) event.getSource()).getScene().getRoot();
if (flag) {
//Revisar animación más adelante
Parent sidebar = FXMLLoader.load(getClass().getResource("/app/fxml/Sidebar.fxml"));
sidebar.translateXProperty();
//
border_pane.setLeft(sidebar);
//
Timeline timeline = new Timeline();
KeyValue kv = new KeyValue(sidebar.translateXProperty(),0,Interpolator.EASE_IN);
KeyFrame kf = new KeyFrame(Duration.seconds(10), kv);
timeline.getKeyFrames().add(kf);
timeline.play();
flag = false;
} else {
border_pane.setLeft(null);
flag = true;
}
}
**#FXML
public void open_admintools_priv(ActionEvent event) throws IOException{
ContentTools = new BorderPane();
BorderPane bp = (BorderPane) ContentTools;
if (flagsc) {
Parent admintools = FXMLLoader.load(getClass().getResource("/app/fxml/AdminTools.fxml"));
bp.setTop(admintools);
flagsc=false;
} else {
ContentTools.setTop(null);
flagsc = true;
}
System.out.println(flagsc);**
}
The method open_admintools_priv should to set visible on top of ContentTools(ContentBorderpane) the Admintools.fxml by pressing a button in another fxml(sidebar.fxml) that I set on the left of my PrincipalBorderPane with the method open_sidebar, that I call creating a new controller of MenuContentController in the SidebarController:
public class SidebarController implements Initializable {
private boolean flagsc = true;
#FXML
private JFXButton condominiobtn;
#FXML
private JFXButton adminbtn;
#FXML
private JFXButton finanzasbtn;
#FXML
private JFXButton reportesbtn;
#FXML
private JFXButton confbtn;
#FXML
private void open_admintools(ActionEvent event) throws IOException{
MenuContentController aux = new MenuContentController();
aux.open_admintools_priv(event);
}
#Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
}
Another problem is that by this way, at the moment I create a MenuContentController, the variable flag is always on true, this variable I use it to set the fxml in borderpane when flag is true, or quit it when flag is false. I don't know if creating an instance of a controller is the way to acces to the objects of that fxml, thanks for your time.

Setting Combobox value when switching screens

I want to switch between FXML-Files with Radiobuttons without losing the Combobox-Selection. "secSelectionModel()" seems to add a Selection, but its not visually shown.
public class Controller {
static SingleSelectionModel cbxSelection;
#FXML private ComboBox<String> cbx = new ComboBox<>();
#FXML private RadioButton radio1 = new RadioButton();
#FXML private RadioButton radio2 = new RadioButton();
#FXML private void cbxFill(){
cbx.getItems().setAll("eins","zwei");
}
#FXML private void screenSwitch() throws IOException {
Stage stage;
Parent root;
if(radio1.isSelected()){
stage=(Stage) radio1.getScene().getWindow();
root = FXMLLoader.load(getClass().getResource("sample.fxml"));
//cbxFill();
cbx.setSelectionModel(cbxSelection);
}
else{
stage=(Stage) radio2.getScene().getWindow();
root = FXMLLoader.load(getClass().getResource("sample2.fxml"));
//cbxFill();
cbx.setSelectionModel(cbxSelection);
}
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
#FXML private void getcbxSelection(){
cbxSelection=cbx.getSelectionModel();
}
}
If Radio2 is selected, I want to switch to Screen2 without losing the Entered Selection in the Combobox.

JavaFX 8: change colour of a specific circle with his own id

I ve created this program that when you click on "create" button other two ButtonBar (called newNode) are created.. inside this Button bar there are a button and a circle. When all is created I would like to change the colour of these two circle when i click another Button. I ve coded something but I can just change the colour of the LAST circle.
public class Controller implements Initializable{
#FXML
private Button btnHaveFun;
#FXML
private ButtonBar ReadSMSBar;
#FXML
private ButtonBar GalleryBar;
#FXML
private ButtonBar FileExplorerBar;
#FXML
private ButtonBar SpyCamBar;
#FXML
private ButtonBar TakeAPictureBar;
#FXML
private ButtonBar TakeAScreenshotBar;
#FXML
private ButtonBar RecordAVideoBar;
#FXML
private ButtonBar SpyWhatsappBar;
#FXML
private ButtonBar KeyLoggerBar;
#FXML
private ButtonBar ScreenStreamBar;
#FXML
private ButtonBar SpyMicrophoneBar;
#FXML
private ButtonBar slaveBar;
#FXML
private VBox slaveVbox;
#FXML
private Circle statusSlave;
private ButtonBar newNode = new ButtonBar();
private Circle c= new Circle();
#Override
public void initialize(URL location, ResourceBundle resources) {
// TODO Auto-generated method stub
}
public void creat(String s){
newNode = new ButtonBar();
c= new Circle();
c.setRadius(11);
c.setStrokeWidth(1);
c.setStroke(Paint.valueOf("#ffffff"));
c.setFill(Paint.valueOf("#15ff00"));
c.setId(s);
newNode.getButtons().addAll(new Button("Mavero"),c);
slaveVbox.getChildren().addAll(newNode) ;
}
#FXML
public void newComp(){
creat("id1");
creat("id2");
}
#FXML
public void change(){
c.setFill(Color.BLACK);
}
}
You could use Node.lookup() to get the Circles using a css selector (or Node.lookupAll for multiple nodes):
void change(String oldId, String newId) {
change(oldId, Color.RED);
change(newId, Color.GREEN);
}
void change(String id, Color color){
Circle circle = (Circle) slaveVbox.lookup('#'+id);
circle.setFill(color);
}
Its simple:
Just add All Circles in a List ->
List<Circle> circles = new ArrayList<>();
public void creat(String s) {
newNode = new ButtonBar();
Circle c = new Circle();
c.setRadius(11);
c.setStrokeWidth(1);
c.setStroke(Paint.valueOf("#ffffff"));
c.setFill(Paint.valueOf("#15ff00"));
c.setId(s);
circles.add(c);
newNode.getButtons().addAll(new Button("Mavero"), c);
slaveVbox.getChildren().addAll(newNode);
}
#FXML
public void newComp() {
creat("id1");
creat("id2");
}
#FXML
public void change() {
for (Circle c : circles) {
c.setFill(Color.BLACK);
}
}

How to insert the value of TextField into TableView in JavaFx

¿Is it possible to insert TextField value into TableView? I would like to insert in "columnCantidad" the value of a TextField. It seems that the field "cantidad" has to exist in a class.
#FXML
private TableView<AbstractConcepto> tablaFactura;
#FXML
private TableColumn<Producto, String> columnReferencia;
#FXML
private TableColumn<AbstractConcepto, String> columnDescripcion;
#FXML
private TableColumn<AbstractConcepto, Float> columnCantidad;
#FXML
private TableColumn<AbstractConcepto, Float> columnPrecioUnitario;
#FXML
private TableColumn<Float, Float> columnPrecioTotal;
#Override
public void mostrarDetalle(Servicio servicio, Producto producto)
{
if(servicio == null)
{
conceptoData.add(producto);
}
if(producto == null)
{
conceptoData.add(servicio);
}
tablaFactura.setItems(conceptoData);
return;
}
private void inicializarTabla()
{
conceptoData = FXCollections.observableArrayList();
columnReferencia.setCellValueFactory(new PropertyValueFactory<Producto, String>("codigo"));
columnDescripcion.setCellValueFactory(new PropertyValueFactory<AbstractConcepto, String>("nombre"));
columnCantidad.setCellValueFactory(new PropertyValueFactory<AbstractConcepto, Float>("cantidad"));
columnPrecioUnitario.setCellValueFactory(new PropertyValueFactory<AbstractConcepto, Float>("pvp"));
return;
}

JavaFX : tableview won't populate from database (ucanaccess)

My application contains a tabpane, each tab is a nested fxml with controller included.
Each fxml file have a tableview that retrieve data from a microsoft access database.
Some of the tables that only have string columns work and get populated but another one(Demandes) that have a integer column and a localdate column wont populate.and i don't know what's causing the problem.
here the nested controller of "Demandes" tab:
public class DemandesController{
#FXML
private TableView<Demande> demandesTable;
#FXML
private TableColumn<Demande, Integer> numColumn;
#FXML
private TableColumn<Demande, String> societeColumn;
#FXML
private TableColumn<Demande, LocalDate> dateDemandeColumn;
#FXML
private TableColumn<Demande, LocalDate> dateSignatureColumn;
#FXML
private TableColumn<Demande, String> villeColumn;
private ObservableList<Demande> demandes = FXCollections.observableArrayList();
private MainApp mainApp;
String BD_URL = mainApp.getBdUrl();
public DemandesController(){
}
public ObservableList<Demande> getBulletins(){
return demandes;
}
#FXML
private void initialize() {
getDemandesData();
numColumn.setCellValueFactory(cellData -> cellData.getValue().numDemandeProperty().asObject());
societeColumn.setCellValueFactory(cellData -> cellData.getValue().societeProperty());
dateDemandeColumn.setCellValueFactory(cellData -> cellData.getValue().dateDemandeProperty());
dateSignatureColumn.setCellValueFactory(cellData -> cellData.getValue().dateSignatureProperty());
villeColumn.setCellValueFactory(cellData -> cellData.getValue().villeProperty());
}
public void setMainApp(MainApp mainApp){
this.mainApp = mainApp;
demandesTable.setItems(getBulletins());
}
public void getDemandesData(){
Task task = new Task<Void>() {
#Override
protected Void call() throws Exception {
try (Connection con = DriverManager.getConnection(BD_URL)) {
Statement stmt = con.createStatement();
ResultSet res = stmt.executeQuery("SELECT * FROM [Demandes-tab]");
while (res.next()) {
int numDemande = res.getInt(1);
String societe = res.getString(2);
LocalDate dateDemande = res.getDate(3)
.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
LocalDate dateSignature = res.getDate(4)
.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
String ville = res.getString(5);
demandes.add(new Demande(numDemande,societe,dateDemande,
dateSignature,ville));
}
}return null;
}
};
new Thread(task).start();
} }
and the parent controller that initialise the nested fxmls and controllers :
public class TabsController{
private MainApp mainApp;
#FXML private AnchorPane Bulletins;
#FXML private BulletinsController BulletinsController;
#FXML private AnchorPane Demandes;
#FXML private DemandesController DemandesController;
#FXML private AnchorPane Personneltest;
#FXML private PersonnelController PersonneltestController;
#FXML private AnchorPane Personnel;
#FXML private PersonnelController PersonnelController;
#FXML private AnchorPane Produit;
#FXML private ProduitController ProduitController;
#FXML private AnchorPane Societes;
#FXML private SocietesController SocietesController;
#FXML
private void initialize() {
}
public void setMainApp(MainApp mainApp) {
this.mainApp = mainApp;
BulletinsController.setMainApp(mainApp);
PersonneltestController.setMainApp(mainApp);
DemandesController.setMainApp(mainApp);
} }
also this was added in the right place :
<Tab text="Demandes">
<content>
<fx:include fx:id="Demandes" source="Demandes.fxml" />
</content>
</Tab>
if someone can tell me why the tableview won't populate that will be a big help. thank you.
ps: oh also i removed the database url just to see if it matters and nothing changed. does that mean that it doesn't connect to the database at all?

Resources