Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8502237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:25:43+00:00 2026-06-11T01:25:43+00:00

I have customized a combobox to show line types, in the selection list, but

  • 0

I have customized a combobox to show line types, in the selection list, but the button just show a text. How can i draw the selected line type in the button.

ComboBox<String> cmb = new ComboBox<String>();
cmb.getItems().addAll("-fx-stroke-dash-array: 12 2 4 2;", "-fx-stroke-dash-array: 2 2;");
cmb.setCellFactory(new Callback<ListView<String>, ListCell<String>>()
    {
        @Override public ListCell<String> call(ListView<String> p)
        {
            return new ListCell<String>()
                {
                    private final Group group;
                    private final Line line;
                    { 
                        setContentDisplay(ContentDisplay.GRAPHIC_ONLY); 
                        group = new Group();
                        group.getChildren().add(new Rectangle(100, 30, Color.WHITE));
                        line = new Line(0, 15, 100, 15);
                        group.getChildren().add(line);
                    }

                    @Override protected void updateItem(String style, boolean empty)
                    {
                        super.updateItem(style, empty);
                        if(style != null && !empty)
                        {
                            line.setStyle(style);
                            setGraphic(group);
                        }
                    }
                };
        }
    });

Here is how it renders:
JavaFX custom combobox

I want to display the selected line sample, instead of the style text “-fx-stroke…”, how can i fix that?

In the selection list there is always an extra space at the left of the line, is possible to get rid of this space?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T01:25:44+00:00Added an answer on June 11, 2026 at 1:25 am

    JavaFX works differently from Swing in that it caches the Nodes created by your CellFactory and only updates them accordingly rather than using them for rendering and throwing them away (which is why you have to implement updateItem). The JFX classes will use one node (or ‘cell’) as the so-called button cell, which is the one just displaying text for you. Basically, you have to invoke cmd.setButtonCell(myCellFactory.call(null));. This will install one of your custom cells as the button cell, and the combo box will automatically update it with the appropriate value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have panel that I have customized. I use it to display text. But
I have a custom list view which contains two text views and on button.
I have a customized show/hide toggle script that I'm using along with CSS3 transitions
I have a customized OpenFileDialog (VS2008, C#, Windows Forms) with a ComboBox. The ComboBox
I have customized the cell with four labels, initially it looks fine but when
I have customized uitableViewcell in which each cell show four data which are related
I have customized my own colors in eclipse but cannot find where to change
On the List.aspx page I have customized the columns with names. And I have
I have customized the button in this way: <Button BorderBrush=Transparent Name=DialButton Click=DialButton_Click > <StackPanel
I am trying to create a customized list field where, I have more then

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.