ComboBox with customized with buttons listcell

Hi all

I would like to create a combobox with a custom listview that contains several controls. The thing is that setAction is consumed by the list of ComboBox popoup and then controls inside are ignored.

There is here an example:

//***************************************************************************************************************

package javafxapplication3;

Import javafx.application.Application;

Import javafx.collections.FXCollections;

Import javafx.collections.ObservableList;

Import javafx.event.ActionEvent;

Import javafx.event.EventHandler;

Import javafx.scene.Scene;

Import javafx.scene.control.Button;

Import javafx.scene.control.ComboBox;

Import javafx.scene.control.ListCell;

Import javafx.scene.control.ListView;

Import javafx.scene.input.MouseEvent;

Import javafx.scene.layout.HBox;

Import javafx.scene.layout.HBoxBuilder;

Import javafx.scene.layout.StackPane;

Import javafx.stage.Stage;

Import javafx.util.Callback;

SerializableAttribute public class JavaFXApplication3 extends Application {}

@Override

{} public void start (point primaryStage)

ObservableList < String > options

= (FXCollections.observableArrayList)

"Option 1"

'Option 2 '.

);

ComboBox < String > comboB = new ComboBox <>(options);

Object obj = comboB.getOnAction ();

comboB.setCellFactory (new reminder < < String > ListView, ListCell < String > > () {})

@Override

public ListCell < String > call (ListView < String > param) {}

last cell ListCell < String > = new ListCell < String > () {}

{

super.setPrefWidth (100);

}

@Override

{} public Sub updateItem (empty string element, Boolean)

super.updateItem point, empty;

If (item! = null) {}

setText (item);

HBox cell = HBoxBuilder.create () .children (createButton (), createButton () infrastructure ();

setGraphic (cell);

} else {}

setText (null);

}

}

};

return the cell;

}

});

Root StackPane = new StackPane();

root.getChildren () .add (comboB);

Scene = new scene (root, 300, 250);

primaryStage.setTitle ("Hello World!");

primaryStage.setScene (scene);

primaryStage.show ();

}

private Button createButton() {}

last button btn = new Button ("Hola");

btn.setOnAction (new EventHandler < ActionEvent > () {}

@Override

{} public void handle (ActionEvent t)

System.out.println ("Does´t work");

}

});

btn.setOnMouseEntered (new EventHandler < MouseEvent > () {}

@Override

{} public void handle (MouseEvent t)

System.out.println ("Works");

}

});

return btn;

}

Public Shared Sub main (String [] args) {}

Launch (args);

}

}

//***************************************************************************************************************

How could I do 'System.out.println ("work of Does´t");' works?

A ComboBox control is used to select an element; from a set of predefined items (displayed in the context menu), or possibly by entering one. You intend something must be selected in your control? If so, it is not clear if something should be selected when the user presses the button. If this isn't the case, then a ComboBox control is not the appropriate control. Something like a menu button can work better.

Assuming you want to use it to make a selection, a menu button might work if you used CustomMenuItems points the menu button and hideOnClick set to false:

import java.util.Arrays;
import java.util.List;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.CustomMenuItem;
import javafx.scene.control.Label;
import javafx.scene.control.MenuButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class ButtonInMenuButtonItem extends Application {

    @Override
    public void start(Stage primaryStage) {
        List options = Arrays.asList("Option 1", "Option 2");
        MenuButton menuButton = new MenuButton("Options");
        for (String option : options) {
            menuButton.getItems().add(createCustomMenuItem(option));
        }
        StackPane root = new StackPane();
        root.getChildren().add(menuButton);
        Scene scene = new Scene(root, 300, 250);
        primaryStage.setTitle("Hello World!");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    private CustomMenuItem createCustomMenuItem(String option) {
        HBox hbox = new HBox(5);
        hbox.getChildren().addAll(createButton(), createButton(), new Label(option));
        CustomMenuItem customMenuItem = new CustomMenuItem(hbox);
        customMenuItem.setHideOnClick(false);
        return customMenuItem ;
    }

    private Button createButton() {
        final Button btn = new Button("Hola");
        btn.setOnAction(new EventHandler() {
            @Override
            public void handle(ActionEvent t) {
                System.out.println("Button pressed");
            }
        });
//        btn.setOnMouseEntered(new EventHandler() {
//            @Override
//            public void handle(MouseEvent t) {
//                System.out.println("Works");
//            }
//        });
        return btn;
    }

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

If you do not want 'selection '. You should maybe use a button from menu above and manage the selection yourself.

Tags: Java

Similar Questions

  • ComboBox with customized view plugin

    Hello

    I used the plugin "Combobox with Custom Display".

    I have similar question

    When I entered the text in the textbox and scroll down using the keyboard button. The party highlight cannot scrolling with scroll.

    The demo link for above question

    http://Apex.Oracle.com/pls/Apex/f?p=35538:4

    kindly help me.

    Thank you

    Shiv says:
    Hello

    I used the plugin "Combobox with Custom Display".

    I have similar question

    When I entered the text in the textbox and scroll down using the keyboard button. The party highlight cannot scrolling with scroll.

    The demo link for above question

    http://Apex.Oracle.com/pls/Apex/f?p=35538:4

    kindly help me.

    Thank you

    Its a bug in the code of the plugin and not related to the APEX.

    I will study the issue and fix my code to resolve this problem, please bookmark this page http://www.apex-plugin.com/oracle-apex-plugins/item-plugin/combobox-with-custom-display_212.html and search for updates.

    Thank you
    Vikram

  • Help with custom radio buttons.

    Before you go all Rube Goldburg thought that I post for a quick reality check.

    Basically, I have a test with several different configurations of coupon and I try to give users an advanced interface to select one they use. Using radio buttons seems the way to go and I inserted my custom images but I have only be able to select by clicking on the buttons. I want the user to be able to click on the image. Unless I'm missing something, I have this feeling that I have to create the four complete custom Boolean buttons with States of 4-6 and then write the code to do that alone is never on at the same time?

    Joint-

    You can change the appearance and the size of the used option button and overlay them on your chart, and then set the transparent parameter. So it looks like they're clicking on custom image but they are clicking on the invisible button on the top of the image.

    But it might be easier to use a ring of photo,

    Photo ring can be changed at runtime to add selections. Where the radio button enum cannot.

  • iPhone 5 volume cannot be reduced with (-) button after update to 9.3.2

    Volume cannot be reduced with button after update to 9.3.2

    Can increase the volume with button until the max volume.

    Cannot lower volume in any application that has sound.

    This on the iPhone 5 with iOS 9.3.2

    Try a Reset: press and hold the sleep/wake button and the Home button at the same time for at least 10 seconds, until the Apple logo appears. -Note: no data will be lost

  • From time to time my roommate ends up getting new toolbars with buttons or apps that I don't want. How I eat these?

    From time to time my roommate ends up getting new toolbars with buttons or apps that I don't want. How I eat these? Thank you!

    Great idea! Thank you!

  • Disconnection of call with button / stop

    Hello

    Is it possible to have call disconnect with button system / stop?

    Ex:. Samsung gives call witness (Home button) and disconnect with (power button)

    Concerning

    Paddy


  • My computer shuts down is no longer with button closure

    My computer shuts down is no longer with button closure. Works only with button on the computer case.

    * original title - system update updates microsoft windows *.

    Hello

    1 are there any changes or updates made on the computer?

    2. what operating system is installed on the computer?

    3. what happens when you try to shut down the computer?

    4. do you get an error message? If Yes, what is the full and exact error message?

    Step 1:

    Try restarting your computer in safe mode and check if the problem persists.

    a. restart your computer.

    b. when the computer starts, you will see your computer hardware are listed. When you see this information begins to tap the F8 on your keyboard key repeatedly until you are presented with the screen Windows Advanced Startup Options.

    c. using the arrow keys, select the Safe Mode option.

    d. press the Enter key on your keyboard to start Windows Safe Mode.

    e. when Windows starts, you will be at a typical logon screen. Connect to your computer and Windows goes into safe mode.

    f. check if you still have the problem.

    If it works fine in safe mode try performing a clean boot in order to find the cause root.

    Step 2:

    See the article about how to start your computer in a clean boot state.
    How to troubleshoot a problem by performing a clean boot in Windows Vista or in Windows 7
    http://support.Microsoft.com/kb/929135

    How to configure Windows XP to start in a "clean boot" State

    http://support.Microsoft.com/kb/310353

    Note: when the diagnosis is complete do not forget to reset the computer to a normal startup.

    If the problem is not resolved, please provide more information to help you best.

  • optical mouse with button magnifying glass

    optical mouse with button magnifying glass

    I have been using Microsoft Notebook Optical Mouse 3000 model 1049, since a few years. It has a maximize button. I would buy the same or a similar mouse (with the magnifying glass button), I'm not. Please tell us which model I should look for in current models, to my email address.

    Hello

    I suggest you check out the link for a list of available Microsoft mouse models below.

    http://www.Microsoft.com/hardware/en-us/mice

    You can also contact the Microsoft Hardware technical support for more information.

    http://www.Microsoft.com/hardware/en-us/support/contact-us

  • Creating a menu with button rollover images

    Hello

    I am building a menu with buttons rollover images. It is the 5 buttons, one under the other.

    I built a class with a background image that changes between the development and the status of non-focus, to make the transfer. To enable the active state, I simply added a transparent gif (width setSpace to cover the entire background).

    The unfocus/update works fine, but when I reached the button up or down, the transparent gif and its area becomes white...

    We can see the background on the right side of the white square...

    Here's the class of the button:

    OK I solved this problem with the help of this thread:

    http://supportforums.BlackBerry.com/Rim/Board/message?board.ID=java_dev&thread.ID=39506

    Thank you

  • How to create a horizontal Gallery with buttons?

    I can't understand how to create a way to show my photos as a horizontal Gallery with buttons to scroll (photos at left), as Elizabeth Gadd photography . Can anyone help?

    Have you looked at the standard slideshow and Lightbox widget or sought another widget "image Carousel"? It's really basic things.

    Mylenium

  • ComboBox with checkbox

    Hi all

    I want to display a combobox with the ablity to select multiple items and also be able to show the elements selected with different visual effects - I think that a checkbox to display selected/United Nations-selected item is more appropriate, but I can live with the alternative, like for example, highlight them selected with 'light green' etc.

    Is it possible to do so under JavaFX?

    Thank you

    DP

    import java.util.Arrays;
    import java.util.List;
    
    import javafx.application.Application;
    import javafx.beans.value.ChangeListener;
    import javafx.beans.value.ObservableValue;
    import javafx.scene.Scene;
    import javafx.scene.control.CheckMenuItem;
    import javafx.scene.control.ListView;
    import javafx.scene.control.MenuButton;
    import javafx.scene.layout.BorderPane;
    import javafx.stage.Stage;
    
    public class MultipleSelectionDropdownTest extends Application {
    
        @Override
        public void start(Stage primaryStage) {
            final MenuButton choices = new MenuButton("Fruit");
            final List checkItems = Arrays.asList(
                new CheckMenuItem("Apples"),
                new CheckMenuItem("Oranges"),
                new CheckMenuItem("Pears"),
                new CheckMenuItem("Grapes"),
                new CheckMenuItem("Mangoes")
            );
            choices.getItems().addAll(checkItems);
    
              // Keep track of selected items
            final ListView selectedItems = new ListView<>();
            for (final CheckMenuItem item : checkItems) {
                item.selectedProperty().addListener(new ChangeListener() {
                    @Override
                    public void changed(ObservableValue obs,
                            Boolean wasPreviouslySelected, Boolean isNowSelected) {
                        if (isNowSelected) {
                            selectedItems.getItems().add(item.getText());
                        } else {
                            selectedItems.getItems().remove(item.getText());
                        }
                    }
                });
            }
    
            BorderPane root = new BorderPane();
            root.setTop(choices);
            root.setCenter(selectedItems);
            primaryStage.setScene(new Scene(root, 600, 400));
            primaryStage.show();
        }
    
        public static void main(String[] args) {
            launch(args);
        }
    }
    
  • How to change the Rectangles with buttons

    I'm working on this example that does not work correctly:

    public class test extends Application
    {
    
        private void init(Stage primaryStage)
        {
    
            Group root = new Group();
            primaryStage.setScene(new Scene(root));
    
            String pillButtonCss = DX57DC.class.getResource("PillButton.css").toExternalForm();
    
            // create 3 toggle buttons and a toogle group for them
            ToggleButton tb1 = new ToggleButton("Left Button");
            tb1.setId("pill-left");
            ToggleButton tb2 = new ToggleButton("Center Button");
            tb2.setId("pill-center");
            ToggleButton tb3 = new ToggleButton("Right Button");
            tb3.setId("pill-right");
    
            final ToggleGroup group = new ToggleGroup();
            tb1.setToggleGroup(group);
            tb2.setToggleGroup(group);
            tb3.setToggleGroup(group);
            // select the first button to start with
            group.selectToggle(tb1);
    
            //////////////////////////////////////////
    
            final VBox vbox = new VBox();
    
            final Rectangle rect1 = new Rectangle(300, 300);
            rect1.setFill(Color.ALICEBLUE);
            final Rectangle rect2 = new Rectangle(300, 300);
            rect2.setFill(Color.AQUA);
            final Rectangle rect3 = new Rectangle(300, 300);
            rect3.setFill(Color.AZURE);
    
            tb1.setUserData(rect1);
            tb2.setUserData(rect2);
            tb3.setUserData(rect3);
    
            group.selectedToggleProperty().addListener(new ChangeListener<Toggle>()
            {
                @Override
                public void changed(ObservableValue<? extends Toggle> ov, Toggle toggle, Toggle new_toggle)
                {
                    if (new_toggle == null)
                    {
                        //rect.setFill(Color.WHITE);
                    }
                    else
                    {
                        vbox.getChildren().addAll((Node[]) group.getSelectedToggle().getUserData());
                        //rect.setFill((Color) group.getSelectedToggle().getUserData());
                    }
                }
            });
    
    
            ///////////////////////////////////////////
    
    
            HBox hBox = new HBox();
            hBox.getChildren().addAll(tb1, tb2, tb3);
            hBox.setPadding(new Insets(20, 20, 260, 20));
            hBox.getStylesheets().add(pillButtonCss);
    
    
    
            vbox.getChildren().add(hBox);
            //vbox.getChildren().add(rect);
    
            root.getChildren().add(vbox);
        }
    
        @Override
        public void start(Stage primaryStage) throws Exception
        {
            init(primaryStage);
            primaryStage.show();
        }
    
        public static void main(String[] args)
        {
            launch(args);
        }
    }
    
    
    

    I want to create several Rectangles (or in which object or object) in which I want to store data. I want to spend the Rectangles (objects) that appear in front of the user by using the buttons. The example that I put in place does not work correctly. Can you tell me what is the right way to implement this?

    REF javafx 2 - How to change the Rectangles with buttons - stack overflow

    You have two problems:

    User data that assign you to each button switches are a node, not a [Node]. Thus, the cast will fail on line 43.

    When the selected toggle changes, you add another Rectangle to the vbox. You want to replace the rectangle that is in the vbox.

    Try

    vbox.getChildren () .setAll ((Node) group.getSelectedToggle () .getUserData ());

  • Creation of ComboBox with the values of the fields

    Hey everyone, it's been a while since my last post.

    I spent some time trying to fill a ComboBox with the values of the 3 fields of different form of google and I was wondering if someone could tell me on common sense.

    Thanks a lot for any idea!

    the general idea would be something like this:

    Get added to a table field values

    var aItems = [];

    aItems.push (getField("Text1").valueAsString);

    aItems.push (getField("Text2").valueAsString);

    aItems.push (getField("Text3").valueAsString);

    Fill the drop-down list with the elements box

    getField("combo1").setItems (aItems);

    Replace domain names with real field names that you use.

    You can start the list with an element that is a single space (if it appears empty) or something like "- select -". You can also make sure you add all the duplicate entries, which would happen if all the field values are the same.

    When did you want this script to run?

  • Conditional confirm dialog with button

    Hi all

    I want to create a dialog box confirming with the "submit" button that can be triggered only if an item is not presented in this page.

    I have a checkbox element in my page called P2_LWF

    I created confirm dialog with button using the code below

    JavaScript:if (confirm ('are you sure you want to continue?')) {
    This.disabled = true; This.Value = 'Submitted...';
    doSubmit ('SUBMIT');

    When I click on the "submit" button I want to start confirming the dialogue only if P2_LWF is not checked.

    How can I make in my application?

    Kind regards
    Year s

    Year s Hi,

    Try now.
    I don't know what you mean by: "...". want to clear the max in the employee area (area report) those offer button or refresh the page. »

    BR,
    Marko Goricki
    http://apexbyg.blogspot.com/

  • With the help of hitTestObject with buttons added in AS

    I would use hitTestObject with buttons spark I create dynamically in Actionscript. I'm confused about this, however. I was testing this code:


    < s:Group id = "MyGroup" >
    < local: id = "button1" x = "100" RectButton = "20" label = "Button1" fill = "0xff0000" / >
    < local: RectButton id = "button2" x = "105" y = "20" label = "Button2" fill = "0x00ffff" / >
    < / s:Group >

    And I had this in the full feature for my test application:
    trace ("button 1 button 2 placement test:"+ button1.hitTestObject (button2) ');

    It returns the value true.

    When I remove the MXML for two buttons and add them to my complete feature like this:
    var button1: RectButton = new RectButton();
    Button1.x = 100;
    Button1.y = 20;
    Button1.label = "Button1";
    Button1.fill = 0xff0000;
    myGroup.addElement (button1);

    var button2: RectButton = new RectButton();
    Button2.x = 105;
    Button2.y = 20;
    Button2.label = "Button2";
    Button2.fill = 0x00ffff;
    myGroup.addElement (button2);

    Then this line:
    trace ("button 1 button 2 placement test:"+ button1.hitTestObject (button2) ');
    Returns false!

    The RectButtonSkin is really simple. It's a SparkSkin with this in it:
    < s:Rect left = "0" right = "0" top = low "0" = "0" height = "1" width = "1" >
    < s:fill >
    < s:SolidColor id = "rectFill" color = "0xffffff" alpha = "0.3" / >
    < / s:fill >
    < / s:Rect >

    And the RectButton is a spark button with a fill attribute.

    Anyone has any ideas on this subject?

    Thank you!
    Anna

    You can call hitTestObject() too early.  Try to wait for the updateComplete on the group event, for example:

    http://ns.Adobe.com/MXML/2009.

    xmlns:s = "library://ns.adobe.com/flex/spark".

    creationComplete = "createElements ()" > "

    Import spark.components.Button;

    Import mx.events.FlexEvent;

    private var asButton1:Button;

    private var asButton2:Button;

    protected function createElements (): void

    {

    asButton1 = new Button();

    asButton1.label = "Button1";

    asButton1.x = 100;

    asButton1.y = 20;

    myGroup.addElement (asButton1);

    asButton2 = new Button();

    asButton2.label = "Button2";

    asButton2.x = 105;

    asButton2.y = 20;

    myGroup.addElement (asButton2);

    too early

    trace (asButton1.hitTestObject (asButton2));

    wait updateComplete trace test

    myGroup.addEventListener (FlexEvent.UPDATE_COMPLETE, traceTest);

    }

    private void traceTest(e:Event):void {}

    trace (asButton1.hitTestObject (asButton2));

    }

    ]]>

Maybe you are looking for