Javafx change Tab X to image icon from url

2020-05-02 07:37发布

How could I change the Tabs close icon X to an image in javafx? I have tried setGraphic(), but it only takes a node... the image i want to set it to is http://eclipse-icons.i24.cc/ovr16/progress_rem.gif

标签: java tabs javafx
1条回答
Animai°情兽
2楼-- · 2020-05-02 08:07

Make the image a valid node using ImageView, but that seems to be for icons.

Tab tab = new Tab();
Image image = new Image("http://eclipse-icons.i24.cc/ovr16/progress_rem.gif");
ImageView iv = new ImageView(image);
tab.setGraphic(iv);    

Get rid of the default shape in CSS or write your own or use a background image

.tab-close-button {
-fx-background-color: transparent;//-fx-mark-color;
-fx-shape:null;
-fx-background-image: url("/progress_rem.gif");
}

You'll have to provide your own click handler without the css shape, or something to click on.

This is what you get with css.using background image for tab close button

查看更多
登录 后发表回答