How to remove close button from tabs in JavaFX - java

I have created some tabs in a TabPane. Each time I make a tab it has got a close(x) button on its right side. I don't want the tabs to be removed from the TtabPane so I have used:
TabPane tabPane = new TabPane();
Tab tab = new Tab("new tab");
tab.setContents(new Label("Please help"));
tabPane.getTabs().add(tab);
tab.setOnCloseRequest(e -> e.consume());
so that it won't be removed. Is there some way not to display this close button on tab.
Any help is appreciated.

You can set the TabClosingPolicy on a TabPane
myTabPane.setTabClosingPolicy(TabClosingPolicy.UNAVAILABLE);
There are the following possibilities:
TabClosingPolicy.ALL_TABS // all tabs can be closed
TabClosingPolicy.SELECTED_TAB // only the selected tab can be closed
TabClosingPolicy.UNAVAILABLE // you cant close
If you are adding classes to myTabPane.getTabs() there is also the possibility to set the class to not be closeable (because it needs to extend from Tab):
setClosable(false);
If you define it in the class which extends from Tab I guess the policy you set will be useless and is overridden.
Link to the oracle doc:
JavaFX 8 TabPane.TabClosingPolicy

You can also define this using FXML by this code:
<TabPane tabClosingPolicy="UNAVAILABLE">

Related

Is there a way to put a anchor component in an context menu in vaadin 14?

Im trying to get a vaadin anchor component inside of an context menu, but I cant get it to work.
I tried it like following:
this.contextMenu.add(anchorFile);
But the menu item inside of the context menu wont appear.
I hope someone can help me.
Thanks in advance
Have you set the text content for your Anchor component?
The proper way to add the Anchor as menu item is this.
ContextMenu menu = new ContextMenu(targetComponent);
Anchor vaadin = new Anchor("https://vaadin.com/","Vaadin");
menu.addItem(vaadin);
add methods also adds the component to the menu, but wont't wrap as menu item. It is more purposed for adding decorative components like dividers etc.
ContextMenu menu = new ContextMenu(targetComponent);
Anchor vaadin = new Anchor("https://vaadin.com/","Vaadin");
menu.add(vaadin);
Moreover with addIten method you can set the event listener for menu item being selected:
ContextMenu menu = new ContextMenu(targetComponent);
Anchor vaadin = new Anchor("https://vaadin.com/","Vaadin");
menu.addItem(vaadin, event -> {
System.out.println("Selected");
});

How to get back the onclick effect on a button in JavaFX

I looked for a solution on this particular issue & found a few ones on Silverlight & JavaScript, but not on JavaFX.
Now on the issue:
I am designing a GUI in JavaFX where I have added two buttons: ADD & REMOVE
I have styled the ADD button using CSS, but it has lost its hovering & onclick effect. I have attached a couple of images for better understanding of the issue
If you look at this photo here, you'll see that when the REMOVE button is clicked, it slightly changes its color to give the effect that it is being clicked currently. Also when the cursor hovers over it, it turns slightly brighter than it usually is.
The code for this button is given below
VBox rightBox = new VBox(remBttn);
rightBox.setPadding(new Insets(10));
rightBox.setAlignment(Pos.CENTER);
remBttn.setPadding(new Insets(100,0,100,0));
remBttn.setPrefWidth(100);
remBttn.setOnAction(
new EventHandler<ActionEvent>()
{
public void handle(ActionEvent ae)
{
myLabel.setText("You Clicked The REMOVE Button");
}
});
remBttn.setFont(Font.font(20));
However, if you look at this photo here, you'll notice that hovering and clicking have no effects on it. I don't know much about CSS, so I copied a snippet of code from a random Website to style my button. But I think that is where I messed it all up.
The code for that give below:
VBox leftBox = new VBox(addBttn);
leftBox.setPadding(new Insets(10));
leftBox.setAlignment(Pos.CENTER);
addBttn.setPadding(new Insets(100,0,100,0));
addBttn.setPrefWidth(100);
addBttn.setStyle("-fx-background-color: #c3c4c4, linear-gradient(#d6d6d6 50%, white 100%), radial-gradient(center 50% -40%, radius 200%, #e6e6e6 45%, rgba(230,230,230,0) 50%); -fx-background-radius: 30; -fx-background-insets: 0,1,1; -fx-text-fill: black; -fx-effect: dropshadow( three-pass-box , rgba(0,0,0,0.6) , 3, 0.0 , 0 , 1 ); -fx-focus-color: transparent; -fx-base: coral;");
So I want to know what methods or properties can be used to bring back the same effects without changing the style.
The moment you change the background of the button,It will lose its default hover and click effect,So I think the better way of doing it is to set the hover and click effect in css.
By the way instead of setting style again in code, just create a css file in your src folder then link it to your scene using this.
scene.getStylesheets().add(getClass().getResource("your_file_name.css").toExternalForm());
Then add an id to your add button using addBttn.setId("addBttn"); Then
refer to it in your_file_name.css like
#addBttn{
/*Your custom default button style*/
}
#addBttn:hover{
/*Your button style on hover*/
}
#addBttn:pressed{
/*Your button style on pressed*/
}
Hope this solves your problem.

JavaFX How to get a children (WebView) from a Tab?

I have just started to do things with JavaFX and I'm trying to 'build' an browser. Right now I have a TabPane with two tabs. One tab has a WebView and the other tab is able to add new tabs. Over the TabPane is a Textfield. When I enter an internet adress I want to load a website in the selected Tab.
My Problem is, that I dont know how to get the Webview inside the selected Tab. I was able to get the selected Tab, but I have no Idea how to get the WebView inside it.
int index = TabPane.getSelectionModel().getSelectedIndex();
Tab selectedTab = TabPane.getTabs().get(index);
You could always call selectedTab.getContent(), and then navigate down through the scene graph hierarchy until you get to the right element. E.g. if your tab content is a BorderPane and the WebView is in the center you could do
BorderPane selectedBorderPane = (BorderPane) selectedTab.getContent();
WebView selectedWebView = (WebView) selectedBorderPane.getCenter();
This is pretty ugly code, though, and you'd have to rewrite it any time you changed the layout, which means your application becomes hard to maintain.
A (much) better way would be to create a variable at the appropriate scope (controller for the view that displays the tab pane, or the class that contains it if you're doing the layout in Java) for the current web view:
private WebView currentWebView ;
Then whenever you create a new tab containing a web view, add a listener to the tab's selectedProperty:
Tab tab = new Tab(...);
// ...
WebView webView = new WebView(...);
// ... layout, etc tab content, etc...
tab.selectedProperty().addListener((obs, wasSelected, isNowSelected) -> {
if (isNowSelected) {
currentWebView = webView ;
}
});
Now currentWebView always references the currently displayed web view. (You will also need to initialize it to the first web view displayed at startup.)

GXT3 Remove tab from a tabpanel/tab container

I am using GXT3 version. I have a screen with tabs where on the first tab I have add button which opens new tab where I do certain functions. After done I need to close the newly opened tab on click of close button which I am not able to do.
To add the new tab I am doing this
tabPanel.add(childPanel, new TabItemConfig("some title"));
where childPanel is a verticalLayoutContainer widget of another class. The close button is in this another class.
How can I remove this new tab?
if I understood your problem, in gxt3 you need pass in the config if your new tab can be closed.
TabItemConfig tabItemConfig = new TabItemConfig("Some Title");
tabItemConfig.setClosable(true);
tabPanel.add(childPanel, tabItemConfig);
So the new tab has a close button.

opption menu Jelly bean

How will it be possible to have a menu button which call option-menus with the following condistions ( must be ):
App hides the titlebar :
requestWindowFeature(Window.FEATURE_NO_TITLE);
the targetversion in Manifest is set to 16 :
android:targetSdkVersion="16"
Some Infos and researches from my side:
Setting targetSdkVersion="10" shows the menu still in the bottom, which I would like to achieve.
Showing the titlebar shows the menubutton in top ( 3 points icon ) and the menu is also callable. But I need to hide the titlebar.
any hints , suggestions ?
thanks & regards
Andreas
Another option is to use slider menu and have it on left or right. You shouldn't include button on action bar (like facebook), you can open menu after item click or onFling event.
There is nice and easy tutorial that I tried:
http://oodlestechnologies.com/blogs/Facebook-Style-Slide-Menu-In-Android

Categories