logo
down
shadow

Error with JavaFX when aplying custom themes to ChoiceBox


Error with JavaFX when aplying custom themes to ChoiceBox

By : user2953068
Date : November 19 2020, 03:59 PM
help you fix your problem When you open the FXML file on SceneBuilder, for AeroFX, win7.css doesn't contain the class choice-box, you see the default modena style applied.
But the problem with AeroFX is it doen't have a customized ChoiceBox control, and when you apply in code AeroFX.style() there is no skin AeroChoiceBoxSkin, and with no skin to apply, it 'disappears'.
code :
public static void style(){
    Application.setUserAgentStylesheet(
        AeroFX.class.getResource("win7.css").toExternalForm());
}


Share : facebook icon twitter icon
javafx choicebox events

javafx choicebox events


By : smart1122
Date : March 29 2020, 07:55 AM
should help you out Add a ChangeListener to the ChoiceBox's selectionmodel and selectedIndexProperty:
code :
final ChoiceBox<String> box = new ChoiceBox<String>();

    box.getItems().add("1");
    box.getItems().add("2");
    box.getItems().add("3");

    box.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() {
      @Override
      public void changed(ObservableValue<? extends Number> observableValue, Number number, Number number2) {
        System.out.println(box.getItems().get((Integer) number2));
      }
    });
JavaFX - Get the value of a ChoiceBox without Lambdas

JavaFX - Get the value of a ChoiceBox without Lambdas


By : Sourav1987
Date : March 29 2020, 07:55 AM
I hope this helps . I'm learning Java for 3 weeks now and Im wondering how I do get the value of the chosen item (just Strings) of a ChoiceBox without lambdas by using a Listener. I dont use lambdas because I want to understand whats behind it. I got the following code: , All these three are identical:
code :
  choiceBox.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<String>()
  {
     @Override
     public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue)
     {
        System.out.println(observable + oldValue + newValue);
     }
  });

  choiceBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
     System.out.println(observable + oldValue + newValue);
  });

  choiceBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> System.out.println(observable + oldValue + newValue));
JavaFX ChoiceBox in a MenuBar

JavaFX ChoiceBox in a MenuBar


By : MATLAB BOOTCAMP
Date : March 29 2020, 07:55 AM
I hope this helps you . Set the Id of the Menu that contains the ChoiceBox to transparent and use the following CSS:
code :
#transparent:hover,
#transparent:focused,
#transparent:showing {
    -fx-background: transparent;
}
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;

public class Foo extends Application {

    @Override
    public void start(Stage stage) throws Exception {
        Menu fileMenu = new Menu("File");

        ChoiceBox<String> languageBox = new ChoiceBox<String>();
        languageBox.getItems().addAll("English", "Deutsch");

        Menu languageMenu = new Menu();
        languageMenu.setId("transparent");
        languageMenu.setGraphic(languageBox);

        MenuBar menuBar = new MenuBar();
        menuBar.getMenus().addAll(fileMenu, languageMenu);

        BorderPane root = new BorderPane();
        root.setTop(menuBar);

        Scene scene = new Scene(root);
        scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());

        stage.setScene(scene);
        stage.setTitle("MCVE");
        stage.setWidth(640);
        stage.setHeight(480);
        stage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }

}
Error: use a ChoiceBox selection to load the content in a second ChoiceBox

Error: use a ChoiceBox selection to load the content in a second ChoiceBox


By : dconrad
Date : March 29 2020, 07:55 AM
To fix this issue I refactored your code a little.
1st Thing: Always set types on Nodes.
code :
final ChoiceBox<String> cb1 = new ChoiceBox();
final ChoiceBox<String> cb2 = new ChoiceBox();
cb2.getSelectionModel( ).selectedIndexProperty( ).addListener(
( ov, oldVal, newVal ) -> {
    trace("cb2 listener");

    // change label
    int optionSelected = newVal.intValue();
    List options  = cb2.getItems();
    String option = options.get(optionSelected).toString();
    label.setText( option );
});
// Set the ChoiceBox 2 listener
cb2.getSelectionModel().selectedItemProperty().addListener(
( ov, oldVal, newVal ) -> {
    trace("cb2 listener");
    // change label                
    label.setText( newVal );
 });
import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.stage.Stage;

/**
 *
 * @author orici
 */
public class MiDoubleChoiceBoxWithDependency extends Application {

    private final Label label = new Label();
    private final String[] contentsA = new String[] {
        "Words 1",
        "Words 2",
        "Words 3"
    };
    private final String[] extra1 = new String[] {
        "AAA",
        "BBB",
        "CCC"
    };
    private final String[] extra2 = new String[] {
        "LLL",
        "MMM",
        "QQQ"
    };
    private final String[] extra3 = new String[] {
        "XXX",
        "YYY",
        "ZZZ"
    };


    public static void main( String[] args ) {
            launch( args );
    }

    @Override
    public void start( Stage stage ) {

        label.setFont( Font.font( "Arial", 25 ));
        label.setText( extra1[0] );


        ////////////////////////////////////////////////////////////////
        // ChoiceBoxes

        ObservableList<String> options1 =
            FXCollections.observableArrayList( extra1 );
        ObservableList<String> options2 =
            FXCollections.observableArrayList( extra2 );
        ObservableList<String> options3 =
            FXCollections.observableArrayList( extra3 );

        // Create the ChoiceBoxes
        final ChoiceBox<String> cb1 = new ChoiceBox(
            FXCollections.observableArrayList( contentsA ));
        final ChoiceBox<String> cb2 = new ChoiceBox();
        cb2.getItems().addAll(options1);

        // Default values for the ChoiceBoxes
        cb1.setValue(contentsA[0]);        // by value
        cb2.getSelectionModel().select( 0 ); // by position


        // Set the ChoiceBox 1 listener
        cb1.getSelectionModel( ).selectedIndexProperty( ).addListener(
            ( ov, oldVal, newVal ) -> {
                trace("cb1 listener");

                // change second ChoiceBox values
                int optionSelected = newVal.intValue();

                if (optionSelected == 0)
                    cb2.getItems().setAll(options1);
                if (optionSelected == 1)
                    cb2.getItems().setAll(options2);
                if (optionSelected == 2)
                    cb2.getItems().setAll(options3);

                // select the item in position 0
                cb2.getSelectionModel().select( 0 ); // by position
            }
        );

        // Set the ChoiceBox 2 listener
        cb2.getSelectionModel().selectedItemProperty().addListener(
            ( ov, oldVal, newVal ) -> {
                trace("cb2 listener");

                // change label                
                label.setText( newVal );
            }
        );


        ////////////////////////////////////////////////////////////////
        // place GUI elements
        HBox hb = new HBox();
        hb.getChildren( ).addAll( cb1, cb2, label );
        hb.setSpacing( 30 );
        hb.setAlignment( Pos.CENTER );
        hb.setPadding( new Insets( 10, 0, 0, 10 ));

        Scene scene = new Scene( hb, 400, 200 );
        scene.setFill( Color.ALICEBLUE );
        stage.setTitle( "2 ChoiceBoxes with control" );
        stage.setScene( scene );
        stage.show();
    }

    private void trace(String str) {
        System.out.println(str);
    }

} //class
JavaFx 2 ChoiceBox with custom item

JavaFx 2 ChoiceBox with custom item


By : Mayur Patel
Date : March 29 2020, 07:55 AM
it should still fix some issue You can specify a StringConverter to convert between your myClass instances and the values displayed in the ChoiceBox.
This is done with the setConverter() method.
Related Posts Related Posts :
  • The type org.openqa.selenium.firefox.FirefoxDriver is not accessible
  • Limitations (drawbacks) of java programming language?
  • Error: ')' expected Error: illegal start of expression
  • TableRowSorter use LookAndFeel of TableHeader, but own Comparator
  • Difference between @GeneratedValue and @GenericGenerator
  • Design Scenario: Smartphone class and will have derived classes like IPhone,AndroidPhone,WindowsMobilePhone can be even
  • Java date parsing without separators?
  • how to map an array of custom type from postgres to java using hibernate
  • Why hibernate always call "update" statement after using "select" statement in MySQL?
  • An interview topic: What can go wrong with this code?
  • How do I regex remove whitespace and newlines from a text, except for when they are in a json's string?
  • How to turn off Preferences > Compiles > User External Build?
  • how to convert arraylist to string array with all items in double quote
  • PMD+Maven+JAVA Error:: Can't find resource rulesets/comments.xml. Make sure the resource is a valid file or URL or is on
  • How to extend AbstractScheduledService.Scheduler
  • Primefaces tabview: set Active Index after some counting
  • Need help in Regex to exclude splitting string within "
  • Get header from HttpUrlConnection object
  • encoding xlsx as base64 and send it as an attachment
  • How to acess HttpServletRequest in Jaas login module in Tomcat
  • How to implement a basic pointer
  • Java Swing Exit Icon?
  • Why onNext has no effect
  • IntelliJ Idea 2018.2 no option for importing gradle project
  • Remove a negative element from an array w/o array.copy
  • Could this prevent overflow in Java?
  • In Java Swing, can I receive Caret events in real time?
  • I need help not using brute force when using JFrames and DrawWindows
  • How do I refactor ArrayList<MyClass> into MyClassLIst?
  • My program keeps saying that the method cannot be resolved
  • BubbleSort -my code returns random addresses
  • JavaFX components inside HTML?
  • Character in Java game not responding
  • Working around access denied in a FileWalking Tree in Java7
  • How to avoid if/else when using multple suppliers?
  • How to pass object from table cell editor to Table Model?
  • Paypal Sandbox payment state pending
  • sejda-console.bat passing parameters with spaces
  • Multiple Consumers Spring Kafka
  • Bitbucket pipeline: environmental variables in build.gradle file not recognized
  • Java static enum method to return a default enum value
  • What is the complexity of empty for loop?
  • Group randomly List of Lists as N subsets with K elements in each
  • How to set texture on a shape drawn by glDrawArrays()?
  • How to make a jlabel resizable according to the window
  • Java Mathematical Expression Syntax
  • assigning values to characters in java
  • Method overriding and Inheritance in java
  • given a set of lists/groups with a series of number, find matching numbers
  • Connection to HID USB device (keyboard and mouse) in android
  • Inject HttpServletRequest in CDI SessionScoped bean
  • Pool game in java - ball collision algorithm
  • Focus ScrollView to selected position programmatically - Android
  • Is it hibernate bug?
  • Glib memory allocation error
  • Android Proguard - step by step
  • Setting the pivot point of a JPanel to its center
  • java check time is greater time
  • how to save a screenshot (matlab)
  • Anti-aliasing filled shapes in libgdx
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org