javafx.scene.control.SingleSelectionModel Java Examples

The following examples show how to use javafx.scene.control.SingleSelectionModel. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MainDesignerController.java    From pmd-designer with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void initLanguageChoicebox() {
    languageChoicebox.getItems().addAll(getSupportedLanguages().sorted().collect(Collectors.toList()));
    languageChoicebox.setConverter(DesignerUtil.stringConverter(Language::getName, AuxLanguageRegistry::findLanguageByNameOrDefault));

    SingleSelectionModel<Language> langSelector = languageChoicebox.getSelectionModel();
    @NonNull Language restored = globalLanguage.getOrElse(defaultLanguage());

    globalLanguage.bind(langSelector.selectedItemProperty());

    langSelector.select(restored);

    Platform.runLater(() -> {
        langSelector.clearSelection();
        langSelector.select(restored); // trigger listener
    });
}
 
Example #2
Source File: CreateTerrainDialog.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
/**
 * Update a list of available path sizes.
 */
@FxThread
private void updatePathSizeValues() {

    final ComboBox<Integer> pathSizeComboBox = getPatchSizeComboBox();
    final SingleSelectionModel<Integer> selectionModel = pathSizeComboBox.getSelectionModel();
    final Integer current = selectionModel.getSelectedItem();

    final ObservableList<Integer> items = pathSizeComboBox.getItems();
    items.clear();

    final ComboBox<Integer> totalSizeComboBox = getTotalSizeComboBox();
    final Integer naxValue = totalSizeComboBox.getSelectionModel().getSelectedItem();

    for (final Integer value : PATCH_SIZE_VARIANTS) {
        if (value >= naxValue) break;
        items.add(value);
    }

    if (items.contains(current)) {
        selectionModel.select(current);
    } else {
        selectionModel.select(items.get(items.size() - 1));
    }
}
 
Example #3
Source File: ServiceMatchingViewController.java    From Corendon-LostLuggage with MIT License 5 votes vote down vote up
/**  
 * Here is the matching tabs set to the right index
 * The index of the tabs are as following:
 *      0:   automatic matching tab 
 *      1:   manual matching tab
 *      2:   potential matching tab
 * 
 * @param tab  index of the wanted matching tab
 * @void - No direct output 
 */
public void setMatchingTab(int tab){
    //check the index (tab) given
    if (tab > 3 || tab < 0){
        tab = AUTO_MATCHING_TAB_INDEX; //set tab to automatich matching
    }
    //get selection of matching tabs
    SingleSelectionModel<Tab> matchingSelectionTabs = matchingTabs.getSelectionModel(); 
    
    //set the right tab
    matchingSelectionTabs.select(tab); 
}
 
Example #4
Source File: RFXTabPane.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
@Override
protected void mouseClicked(MouseEvent me) {
    TabPane tp = (TabPane) node;
    SingleSelectionModel<Tab> selectionModel = tp.getSelectionModel();
    Tab selectedTab = selectionModel.getSelectedItem();
    if (selectedTab != null && prevSelection != selectionModel.getSelectedIndex()) {
        recorder.recordSelect(this, getTextForTab(tp, selectedTab));
    }
    prevSelection = selectionModel.getSelectedIndex();
}
 
Example #5
Source File: GenerateTangentsDialog.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@Override
@FxThread
protected void createContent(@NotNull final GridPane root) {
    super.createContent(root);

    final Label algorithmTypeLabel = new Label(Messages.GENERATE_TANGENTS_DIALOG_ALGORITHM_LABEL + ":");
    algorithmTypeLabel.prefWidthProperty().bind(root.widthProperty().multiply(DEFAULT_LABEL_W_PERCENT3));

    algorithmTypeComboBox = new ComboBox<>(GenerateTangentsDialog.ALGORITHM_TYPES);
    algorithmTypeComboBox.prefWidthProperty().bind(root.widthProperty().multiply(DEFAULT_FIELD_W_PERCENT3));

    final SingleSelectionModel<AlgorithmType> selectionModel = algorithmTypeComboBox.getSelectionModel();
    selectionModel.select(AlgorithmType.MIKKTSPACE);

    final Label splitMirroredLabel = new Label(Messages.GENERATE_TANGENTS_DIALOG_SPLIT_MIRRORED + ":");
    splitMirroredLabel.prefWidthProperty().bind(root.widthProperty().multiply(DEFAULT_LABEL_W_PERCENT3));

    splitMirroredCheckBox = new CheckBox();
    splitMirroredCheckBox.disableProperty().bind(selectionModel.selectedItemProperty().isNotEqualTo(AlgorithmType.STANDARD));
    splitMirroredCheckBox.prefWidthProperty().bind(root.widthProperty().multiply(DEFAULT_FIELD_W_PERCENT3));

    root.add(algorithmTypeLabel, 0, 0);
    root.add(algorithmTypeComboBox, 1, 0);
    root.add(splitMirroredLabel, 0, 1);
    root.add(splitMirroredCheckBox, 1, 1);

    FXUtils.addClassTo(algorithmTypeLabel, splitMirroredLabel, CssClasses.DIALOG_DYNAMIC_LABEL);
    FXUtils.addClassTo(algorithmTypeComboBox, splitMirroredCheckBox, CssClasses.DIALOG_FIELD);
}
 
Example #6
Source File: RoleSelectionTest.java    From triplea with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private SingleSelectionModel<String> createSelectionModelMock(
    final ComboBox<String> comboBox, final int index) {
  final SingleSelectionModel<String> mock = mock(SingleSelectionModel.class);
  when(comboBox.getSelectionModel()).thenReturn(mock);
  when(mock.getSelectedIndex()).thenReturn(index);
  return mock;
}
 
Example #7
Source File: MutableTabPane.java    From pmd-designer with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public SingleSelectionModel<Tab> getSelectionModel() {
    return tabPane.getSelectionModel();
}
 
Example #8
Source File: TabsDemo.java    From JFoenix with Apache License 2.0 4 votes vote down vote up
@Override
public void start(Stage primaryStage) {
    primaryStage.setTitle("Tabs");

    JFXTabPane tabPane = new JFXTabPane();

    Tab tab = new Tab();
    tab.setText(msg);
    tab.setContent(new Label(TAB_0));

    tabPane.getTabs().add(tab);
    tabPane.setPrefSize(300, 200);
    Tab tab1 = new Tab();
    tab1.setText(TAB_01);
    tab1.setContent(new Label(TAB_01));

    tabPane.getTabs().add(tab1);

    SingleSelectionModel<Tab> selectionModel = tabPane.getSelectionModel();
    selectionModel.select(1);

    JFXButton button = new JFXButton("New Tab");
    button.setOnMouseClicked((o) -> {
        Tab temp = new Tab();
        int count = tabPane.getTabs().size();
        temp.setText(msg + count);
        temp.setContent(new Label(TAB_0 + count));
        tabPane.getTabs().add(temp);
    });

    tabPane.setMaxWidth(500);

    HBox hbox = new HBox();
    hbox.getChildren().addAll(button, tabPane);
    hbox.setSpacing(50);
    hbox.setAlignment(Pos.CENTER);
    hbox.setStyle("-fx-padding:20");

    Group root = new Group();
    Scene scene = new Scene(root, 700, 250);
    root.getChildren().addAll(hbox);
    scene.getStylesheets().add(TabsDemo.class.getResource("/css/jfoenix-components.css").toExternalForm());

    primaryStage.setTitle("JFX Tabs Demo");
    primaryStage.setScene(scene);
    primaryStage.show();
}
 
Example #9
Source File: MenuView.java    From JFX-Browser with MIT License 3 votes vote down vote up
private void addAndSelectNewTab(ObservableList<Tab> tabs, Tab tab2, SingleSelectionModel<Tab> selectedTab, SingleSelectionModel<Tab> fxSelectedTab
		,int selectedTabIndex) {
	// TODO Auto-generated method stub


	Platform.runLater(new Runnable() {
		@Override
		public void run() {
			
			

			for(int a=0; a<tabs.size();a++){
				
				String openTabName = tabs.get(a).getText();
				
				if(openTabName.equals("History") 		|| 
						openTabName.equals("Bookmarks") ||
						openTabName.equals("Downloads") ||
						openTabName.equals("Setting"))
					{
				
					//	fxSelectedTab.select(selectedTabIndex);
						System.out.println("Tab index:"+ selectedTabIndex);
						
						selectedTab.select(a);
						
						return;
					
					}
				
			}
			fxSelectedTab.select(selectedTabIndex);
			tabs.add(tabs.size() - 1, tab);
			selectedTab.select(tab);
			getBookMarkView();

		}
	});	
}
 
Example #10
Source File: MainController.java    From JFX-Browser with MIT License 3 votes vote down vote up
public void creatNewTab(TabPane tabpane, Tab addNewTab) {

		Tab tab = new Tab("New tab");


		try {
			tab.setContent(FXMLLoader.load(getClass().getResource(Main.FXMLS+"Tab.fxml")));
			// tab.setText(TabController.getWebEngine().getTitle());

		} catch (IOException e) {
			System.out.println("Exception: New tab click but not working in TabPaneView Class");
		}

		tab.getStyleClass().addAll("tab-pane");

		ObservableList<Tab> tabs = tabpane.getTabs();
		
		Platform.runLater(new Runnable() {
			@Override
			public void run() {
				
				tabs.add(tabs.size() - 1, tab);
				
				SingleSelectionModel<Tab> selectedTab = tabpane.getSelectionModel();
				selectedTab.select(tab);

			}
		});

	}