下面列出了怎么用javafx.scene.control.TabPane的API类实例代码及写法,或者点击链接到github查看源代码。
private DemoTab(String title, String sourceFile) throws Exception {
super(title);
setClosable(false);
TabPane content = new TabPane();
setContent(content);
content.setSide(Side.BOTTOM);
Tab widgets = new Tab("Widgets");
widgets.setClosable(false);
URL location = getClass().getResource(sourceFile);
FXMLLoader fxmlLoader = new FXMLLoader(location);
Node node = fxmlLoader.load();
widgets.setContent(node);
Tab source = new Tab("Source");
source.setClosable(false);
XMLEditor editor = new XMLEditor();
editor.setEditable(false);
String text = IOUtils.toString(getClass().getResourceAsStream(sourceFile));
editor.setText(text);
source.setContent(editor);
content.getTabs().addAll(widgets, source);
}
public GlobalUI(){
globalGridPane = new GridPane();
// dataCollectionUI = new DataCollectionUI();
dataManipulationUI = new DataManipulationUI();
eventDetectionUI = new EventDetectionUI();
influenceAnalysisUI = new InfluenceAnalysisUI();
logUI = new LogUI();
menuBar();
tabPane = new TabPane();
tabPane.setTabClosingPolicy(TabPane.TabClosingPolicy.UNAVAILABLE);
// Tab dataCollectionTab = new Tab("Data Collection");
// dataCollectionTab.setContent(dataCollectionUI.grid);
Tab dataManipulationTab = new Tab("Data Manipulation");
dataManipulationTab.setContent(dataManipulationUI.grid);
Tab eventTab = new Tab("Event Detection");
eventTab.setContent(eventDetectionUI.grid);
Tab influenceTab = new Tab("Influence Analysis");
influenceTab.setContent(influenceAnalysisUI.grid);
tabPane.getTabs().addAll(dataManipulationTab,eventTab,influenceTab);
tabPane.getSelectionModel().select(0);
globalGridPane.add(globalMenu,0,0);
globalGridPane.add(tabPane,0,1);
globalGridPane.add(logUI.logGrid,0,2);
LogUI.addLogEntry("Application started - available cores: "+Configuration.numberOfCores+", workspace: "+Configuration.workspace);
}
/**
* creates the tab pane if required, and adds a tab with the client display
*
* @param clientdisplay the display to show
*/
private void setupDisplay(ClientDisplay clientdisplay) {
// initiates the tabpane if called for the first time
if (this.tabpane == null) {
this.tabpane = new TabPane();
this.tabpane.setBackground(new Background(new BackgroundFill(Color.WHITE, null, null)));
this.tabpane.setTabClosingPolicy(TabPane.TabClosingPolicy.ALL_TABS);
this.tabpane.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> ov, Number oldValue, Number newValue) {
int index = newValue.intValue();
activedisplayindex = index;
logger.warning(" --> Set active display index afterselection to " + index);
}
});
}
displayTab(clientdisplay);
}
@Override
public Node getNode(
PageActionManager actionmanager,
CPageData inputdata,
Window parentwindow,
TabPane[] parenttabpanes,
CollapsibleNode nodetocollapsewhenactiontriggered) {
CChoiceFieldValue[] currentchoice = null;
ArrayList<String> restrictedvalues = null;
if (this.multipledefaultvaluecode != null) {
currentchoice = new CChoiceFieldValue[multipledefaultvaluecode.length];
for (int i = 0; i < this.multipledefaultvaluecode.length; i++) {
currentchoice[i] = findChoiceFromStoredValue(multipledefaultvaluecode[i]);
}
}
if (this.multipledefaultvaluecode==null) if (this.preselectedvalues.size()>0) {
currentchoice = new CChoiceFieldValue[this.preselectedvalues.size()];
for (int i=0;i<this.preselectedvalues.size();i++) currentchoice[i] = this.preselectedvalues.get(i);
}
choicefield = new ChoiceField(actionmanager, compactshow, twolines, label, helper, isactive, iseditable, false,
values, currentchoice, restrictedvalues);
Node node = choicefield.getNode();
this.checkboxpanel = choicefield.getCheckBoxList();
return node;
}
@Override
public Node getNode(
PageActionManager actionmanager,
CPageData inputdata,
Window parentwindow,
TabPane[] parenttabpanes,
CollapsibleNode nodetocollapsewhenactiontriggered) {
Pane thispane = CComponentBand.returnBandPane(direction);
this.bandpane = thispane;
if (this.minwidth != 0)
thispane.setMinWidth(this.minwidth);
for (int i = 0; i < elements.size(); i++) {
Node currentnode = elements.get(i).getNode(actionmanager, inputdata, parentwindow, parenttabpanes,nodetocollapsewhenactiontriggered);
// if node is null (e.g. CObjectIdStorage), then do not add it to the graphic
if (currentnode != null)
thispane.getChildren().add(currentnode);
}
return thispane;
}
@Override
public Node getNode(
PageActionManager actionmanager,
CPageData inputdata,
Window parentwindow,
TabPane[] parenttabpanes,
CollapsibleNode nodetocollapsewhenactiontriggered) {
// gets id data
DataElt thiselement = inputdata.lookupDataElementByName(datareference.getName());
if (thiselement == null)
throw new RuntimeException("could not find any page data with name = " + datareference.getName());
if (!thiselement.getType().equals(datareference.getType()))
throw new RuntimeException(
String.format("page data with name = %s does not have expected %s type, actually found %s",
datareference.getName(), datareference.getType(), thiselement.getType()));
ObjectIdDataElt thisidelement = (ObjectIdDataElt) thiselement;
this.payload = thisidelement;
// returns null as a widget
return null;
}
@Override
public Node getNode(
PageActionManager actionmanager,
CPageData inputdata,
Window parentwindow,
TabPane[] parenttabpanes,
CollapsibleNode nodetocollapsewhenactiontriggered) {
Node payloadnode = payload.getNode(actionmanager, inputdata, parentwindow, parenttabpanes,
(closewheninlineactioninside ? this : null));
collapsiblepane = new TitledPane(this.title, payloadnode);
collapsiblepane.setCollapsible(true);
collapsiblepane.setExpanded(this.openbydefault);
collapsiblepane.setBorder(Border.EMPTY);
collapsiblepane.setAnimated(false);
return collapsiblepane;
}
@Override
public Node getNode(
PageActionManager actionmanager,
CPageData inputdata,
Window parentwindow,
TabPane[] parenttabpanes,
CollapsibleNode nodetocollapsewhenactiontriggered) {
dataarray = getExternalContent(inputdata, datareference);
Pane objectbandpane = CComponentBand.returnBandPane(CComponentBand.DIRECTION_DOWN);
for (int i = 0; i < this.dataarray.getObjectNumber(); i++) {
ObjectDataElt thisobject = this.dataarray.getObjectAtIndex(i);
Node thisobjectnode = CObjectDisplay.generateObjectDisplay(thisobject, this.nodepath, payloadlist, false,
true, actionmanager, null, null, inputdata, parentwindow, parenttabpanes,nodetocollapsewhenactiontriggered);
objectbandpane.getChildren().add(thisobjectnode);
Callback callback = new CObjectBandCallback(i);
if (actiongroup != null) {
CPageNode thisactiongroup = actiongroup.deepcopyWithCallback(callback);
objectbandpane.getChildren().add(thisactiongroup.getNode(actionmanager, inputdata, parentwindow,
parenttabpanes, nodetocollapsewhenactiontriggered));
}
}
return objectbandpane;
}
@Override
@SneakyThrows
public Tab getRoot(RequestContainer request) {
val script = request.getAspect(ScriptingAspect.class).get();
Tab preTab = getTab(script::getPreRequestScript, script::setPreRequestScript, "Before Request");
Tab postTab = getTab(script::getPostRequestScript, script::setPostRequestScript, "After Request");
TabPane tabs = new TabPane(preTab, postTab);
tabs.getSelectionModel().select(1); //default to show after request script
tabs.setSide(Side.LEFT);
tabs.getStyleClass().add("options-tabs");
tabs.tabMinWidthProperty().setValue(20);
tabs.tabMaxWidthProperty().setValue(20);
tabs.tabMinHeightProperty().setValue(150);
tabs.tabMaxHeightProperty().setValue(150);
tabs.setTabClosingPolicy(TabPane.TabClosingPolicy.UNAVAILABLE);
return new Tab("Scripting", tabs);
}
public OptionsDialogFxml(OptionsDialog controller){
setHeading(label("Options"));
var tabs = controller.tabs = new TabPane();
tabs.setId("tabs");
// tabs.setRotateGraphic(true);
tabs.setSide(Side.LEFT);
tabs.getStyleClass().add("options-tabs");
tabs.setPrefHeight(400.0);
tabs.setPrefWidth(400.0);
//javafx setters seem to be broken, have to use property for these configs
// tabs.setTabMinWidth(40);
// tabs.setTabMaxWidth(40);
tabs.tabMinWidthProperty().setValue(40);
tabs.tabMaxWidthProperty().setValue(40);
// tabs.setMinHeight(150);
// tabs.setTabMaxHeight(150);
tabs.tabMinHeightProperty().setValue(150);
tabs.tabMaxHeightProperty().setValue(150);
tabs.setTabClosingPolicy(TabPane.TabClosingPolicy.UNAVAILABLE);
setBody(tabs);
setActions(cancel(controller::onClose, "Close"));
}
@Start
public void setupStage(Stage stage) {
NotesAspectEditor sut = new NotesAspectEditor();
noteAspect = new NotesAspect();
noteAspect.setNote("first");
RequestContainer request = new RequestContainer() {
@Override
public String getType() {
return "";
}};
request.addAspect(noteAspect);
Tab root = sut.getRoot(request);
stage.setScene(new Scene(new TabPane(root)));
stage.show();
}
@Override
public TemplateGuiActionsHandler<KafkaListenerConfig> createListenerConfigListViewActionHandler(AnchorPane rightContentPane,
TabPane masterTabPane,
Tab tab,
ListView<KafkaListenerConfig> listView,
ListView<KafkaTopicConfig> topicConfigListView,
ControllerProvider repository) {
return new ListenerConfigGuiActionsHandler(new TabPaneSelectionInformer(masterTabPane, tab),
new ListViewActionsHandler<>(interactor, listView),
modelDataProxy,
repository,
rightContentPane,
topicConfigListView,
applicationPorts.getListeners(),
new ToFileSaver(interactor));
}
public TabSample() {
BorderPane borderPane = new BorderPane();
final TabPane tabPane = new TabPane();
tabPane.setPrefSize(400, 400);
tabPane.setSide(Side.TOP);
tabPane.setTabClosingPolicy(TabPane.TabClosingPolicy.UNAVAILABLE);
final Tab tab1 = new Tab();
tab1.setText("Tab 1");
final Tab tab2 = new Tab();
tab2.setText("Tab 2");
final Tab tab3 = new Tab();
tab3.setText("Tab 3");
final Tab tab4 = new Tab();
tab4.setText("Tab 4");
tabPane.getTabs().addAll(tab1, tab2, tab3, tab4);
borderPane.setCenter(tabPane);
getChildren().add(borderPane);
}
private TabPane createTabPane() {
tabPane = new TabPane();
tabPane.setId("ConfigurationTabPane");
tabPane.setTabClosingPolicy(TabClosingPolicy.UNAVAILABLE);
layouts = mpfConfigurationInfo.getProperties(this);
for (IPropertiesLayout layout : layouts) {
String name = layout.getName();
Node content = layout.getContent();
content.getStyleClass().add(StyleClassHelper.BACKGROUND);
Tab tab = new Tab(name, content);
tab.setId(name);
tab.setGraphic(layout.getIcon());
tabPane.getTabs().add(tab);
}
VBox.setVgrow(tabPane, Priority.ALWAYS);
return tabPane;
}
@Override
public boolean marathon_select(String tab) {
Matcher matcher = CLOSE_PATTERN.matcher(tab);
boolean isCloseTab = matcher.matches();
tab = isCloseTab ? matcher.group(1) : tab;
TabPane tp = (TabPane) node;
ObservableList<Tab> tabs = tp.getTabs();
for (int index = 0; index < tabs.size(); index++) {
String current = getTextForTab(tp, tabs.get(index));
if (tab.equals(current)) {
if (isCloseTab) {
closeTab(tabs.get(index));
return true;
}
tp.getSelectionModel().select(index);
return true;
}
}
return false;
}
public TabSample() {
BorderPane borderPane = new BorderPane();
final TabPane tabPane = new TabPane();
tabPane.setPrefSize(400, 400);
tabPane.setSide(Side.TOP);
tabPane.setTabClosingPolicy(TabPane.TabClosingPolicy.UNAVAILABLE);
final Tab tab1 = new Tab();
tab1.setText("Tab 1");
final Tab tab2 = new Tab();
tab2.setText("Tab 2");
final Tab tab3 = new Tab();
tab3.setText("Tab 3");
final Tab tab4 = new Tab();
tab4.setText("Tab 4");
tabPane.getTabs().addAll(tab1, tab2, tab3, tab4);
borderPane.setCenter(tabPane);
getChildren().add(borderPane);
}
@Test
public void getText() throws Throwable {
TabPane tabPane = (TabPane) getPrimaryStage().getScene().getRoot().lookup(".tab-pane");
LoggingRecorder lr = new LoggingRecorder();
List<String> text = new ArrayList<>();
Platform.runLater(new Runnable() {
@Override
public void run() {
RFXTabPane rfxTabPane = new RFXTabPane(tabPane, null, null, lr);
tabPane.getSelectionModel().select(1);
rfxTabPane.mouseClicked(null);
text.add(rfxTabPane.getAttribute("text"));
}
});
new Wait("Waiting for tab pane text.") {
@Override
public boolean until() {
return text.size() > 0;
}
};
AssertJUnit.assertEquals("Tab 2", text.get(0));
}
/**
* Save the data access state to the graph.
* <p>
* Currently only global parameters are saved.
*
* @param tabs The TabPane
* @param graph The active graph to save the state to
*/
public static void saveDataAccessState(final TabPane tabs, final Graph graph) {
if (graph != null) {
// buildId the data access state object
final DataAccessState dataAccessState = new DataAccessState();
for (final Tab step : tabs.getTabs()) {
dataAccessState.newTab();
final QueryPhasePane pluginPane = (QueryPhasePane) ((ScrollPane) step.getContent()).getContent();
for (final Map.Entry<String, PluginParameter<?>> param : pluginPane.getGlobalParametersPane().getParams().getParameters().entrySet()) {
final String id = param.getKey();
final PluginParameter<?> pp = param.getValue();
final String value = pp.getStringValue();
if (value != null) {
dataAccessState.add(id, value);
}
}
}
// save the state onto the graph
WritableGraph wg = null;
try {
wg = graph.getWritableGraph("Update Data Access State", true);
final int dataAccessStateAttribute = DataAccessConcept.MetaAttribute.DATAACCESS_STATE.ensure(wg);
wg.setObjectValue(dataAccessStateAttribute, 0, dataAccessState);
} catch (InterruptedException ex) {
Exceptions.printStackTrace(ex);
Thread.currentThread().interrupt();
} finally {
if (wg != null) {
wg.commit();
}
}
}
}
public TabPane getTabPaneView(TabPane tabpane, Tab addNewTab) {
tabpane.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Tab>() {
@Override
public void changed(ObservableValue<? extends Tab> ov, Tab t, Tab newSelectedTab) {
// Closeing tab if first index tab close and size will be the 2
// https://docs.oracle.com/javase/8/javafx/api/index.html?javafx/scene/package-summary.html
if (tabPane.getTabs().size() == 1) {
Platform.exit();
}
// The current tab title is set the stage title
//MainClass.getStage().setTitle(tabPane.getSelectionModel().getSelectedItem().getText());
//The above line was just setting the name of window but according to the requirement we
// just set the fixed name of browser Jfx Browser
if (newSelectedTab == addNewTab) {
// ---------------New tab is created --------------------
Platform.runLater(new Runnable() {
@Override
public void run() {
creatNewTab(tabpane, addNewTab);
}
});
}
}
});
return tabpane;
}
@Override
public void start(Stage primaryStage) {
Tab f = makeTab("Files", "File system view here");
Tab t = makeTab("Type Hierarchy","Type hierarchy view here");
Tab d = makeTab("Debug","Debug view here");
Tab p = makeTab("Properties","Ah, the ubiquitous 'properties' panel");
Tab c = makeTab("Console","Console output here");
Tab o = makeTab("Outline","Outline of fields/methods view here");
TabPane left = new TabPane(f,t,d);
TabUtil.makeDroppable(left); //////////////// see
TabPane right = new TabPane(p,c,o);
TabUtil.makeDroppable(right); /////////////// see
left.setStyle("-fx-border-color: black;");
right.setStyle("-fx-border-color: black;");
BorderPane main = new BorderPane();
main.setPadding(new Insets(0, 20, 0, 20));
main.setTop(new Label("Menubar and toolbars"));
main.setLeft(left);
main.setCenter(new Label("Central work area here"));
main.setRight(right);
main.setBottom(new Label("Statusbar"));
primaryStage.setScene(new Scene(main, 800, 600));
primaryStage.show();
}
@Override
public Node getNode(
PageActionManager actionmanager,
CPageData inputdata,
Window parentwindow,
TabPane[] parenttabpanes,
CollapsibleNode nodetocollapsewhenactiontriggered) {
this.parentwindow = parentwindow;
inputdata.addInlineActionDataRef(inlineactiondataref);
return null;
}
private void initializeCenterLayout() {
SplitPane centerSplitLayout = new SplitPane();
centerSplitLayout.setDividerPosition(0, 0.25);
this.pluginTabPane = new TabPane();
centerSplitLayout.getItems().add(this.pluginTabPane);
if (this.mainPlugin != null) {
centerSplitLayout.getItems().add(this.mainPlugin.getView().getNode());
}
this.rootLayout.setCenter(centerSplitLayout);
}
public void tabPaneChangeListener(TabPane tabpane) {
tabpane.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Tab>() {
@Override
public void changed(ObservableValue<? extends Tab> ov, Tab t, Tab newSelectedTab) {
ham.hideHamburgerPane();
}
});
}
@Override
public MenuBar getNode(
PageActionManager actionmanager,
CPageData inputdata,
Window parentwindow,
TabPane[] parenttabpanes,
CollapsibleNode nodetocollapsewhenactiontriggered) {
MenuBar menubar = new MenuBar();
menubar.setStyle("-fx-base: #ffffff; -fx-hover-base: #ddeeff;");
for (int i = 0; i < listofmenus.size(); i++) {
menubar.getMenus().add(listofmenus.get(i).getMenu(actionmanager, inputdata, parentwindow));
}
return menubar;
}
@Override
public Node getNode(
PageActionManager actionmanager,
CPageData inputdata,
Window parentwindow,
TabPane[] parenttabpanes,
CollapsibleNode nodetocollapsewhenactiontriggered) {
Separator separator = new Separator();
if (!horizontal)
separator.setOrientation(Orientation.VERTICAL);
return separator;
}
/**
* Constructs a blank frame with a desktop pane but no diagram window.
*
* @param pMainStage The main stage used by the UMLEditor
*/
public EditorFrame(Stage pMainStage)
{
aMainStage = pMainStage;
aRecentFiles.deserialize(Preferences.userNodeForPackage(UMLEditor.class).get("recent", "").trim());
MenuBar menuBar = new MenuBar();
setTop(menuBar);
TabPane tabPane = new TabPane();
tabPane.getSelectionModel().selectedItemProperty().addListener((pValue, pOld, pNew) -> setMenuVisibility());
setCenter( tabPane );
List<NewDiagramHandler> newDiagramHandlers = createNewDiagramHandlers();
createFileMenu(menuBar, newDiagramHandlers);
createEditMenu(menuBar);
createViewMenu(menuBar);
createHelpMenu(menuBar);
setMenuVisibility();
aWelcomeTab = new WelcomeTab(newDiagramHandlers);
showWelcomeTabIfNecessary();
setOnKeyPressed(e ->
{
if( !isWelcomeTabShowing() && e.isShiftDown() )
{
getSelectedDiagramTab().shiftKeyPressed();
}
});
setOnKeyTyped(e ->
{
if( !isWelcomeTabShowing())
{
getSelectedDiagramTab().keyTyped(e.getCharacter());
}
});
}
public SVRealNodeAdapter(final Node node, final boolean collapseControls, final boolean collapseContentControls) {
super(ConnectorUtils.nodeClass(node), node.getClass().getName());
this.node = node;
this.collapseControls = collapseControls;
this.collapseContentControls = collapseContentControls;
boolean mustBeExpanded = !(node instanceof Control) || !collapseControls;
if (!mustBeExpanded && !collapseContentControls) {
mustBeExpanded = node instanceof TabPane || node instanceof SplitPane || node instanceof ScrollPane || node instanceof Accordion || node instanceof TitledPane;
}
setExpanded(mustBeExpanded);
}
public SVRemoteNodeAdapter(final Node node, final boolean collapseControls, final boolean collapseContentControls, final boolean fillChildren, final SVRemoteNodeAdapter parent) {
super(ConnectorUtils.nodeClass(node), node.getClass().getName());
boolean mustBeExpanded = !(node instanceof Control) || !collapseControls;
if (!mustBeExpanded && !collapseContentControls) {
mustBeExpanded = node instanceof TabPane || node instanceof SplitPane || node instanceof ScrollPane || node instanceof Accordion || node instanceof TitledPane;
}
setExpanded(mustBeExpanded);
this.id = node.getId();
this.nodeId = ConnectorUtils.getNodeUniqueID(node);
this.focused = node.isFocused();
if (node.getParent() != null && parent == null) {
this.parent = new SVRemoteNodeAdapter(node.getParent(), collapseControls, collapseContentControls, false, null);
} else if (parent != null) {
this.parent = parent;
}
/**
* Check visibility and mouse transparency after calculating the parent
*/
this.mouseTransparent = node.isMouseTransparent() || (this.parent != null && this.parent.isMouseTransparent());
this.visible = node.isVisible() && (this.parent == null || this.parent.isVisible());
/**
* TODO This should be improved
*/
if (fillChildren) {
nodes = ChildrenGetter.getChildren(node)
.stream()
.map(childNode -> new SVRemoteNodeAdapter(childNode, collapseControls, collapseContentControls, true, this))
.collect(Collectors.toList());
}
}
@Override
public TemplateGuiActionsHandler<KafkaBrokerConfig> createBrokerConfigListViewActionHandler(AnchorPane rightContentPane,
TabPane masterTabPane,
Tab tab,
ListView<KafkaBrokerConfig> listView,
ControllerProvider repository) {
return new BrokerConfigGuiActionsHandler(new TabPaneSelectionInformer(masterTabPane, tab),
new ListViewActionsHandler<>(interactor, listView),
interactor,
modelDataProxy,
repository,
rightContentPane,
appStage);
}
@Override
public TemplateGuiActionsHandler<KafkaTopicConfig> createTopicConfigListViewActionHandler(AnchorPane rightContentPane,
TabPane masterTabPane,
Tab tab,
ListView<KafkaTopicConfig> listView,
ControllerProvider repository,
ListView<KafkaBrokerConfig> brokerConfigListView) {
return new TopicConfigGuiActionsHandler(new TabPaneSelectionInformer(masterTabPane, tab),
new ListViewActionsHandler<>(interactor, listView),
modelDataProxy,
repository,
rightContentPane,
brokerConfigListView);
}