i extend post of tabpanes implementation.
i'm interested somehow possible drag tabpanes mouse in order change position of tabpane mouse drag. basic explanation how can implemented highly appreciated.
import javafx.application.application; import javafx.geometry.orientation; import javafx.scene.node; import javafx.scene.parent; import javafx.scene.scene; import javafx.scene.control.splitpane; import javafx.scene.control.tab; import javafx.scene.control.tabpane; import javafx.scene.control.textarea; import javafx.scene.layout.borderpane; import javafx.stage.stage; public class fxsplittabs extends application{ @override public void start(stage stage) throws exception { stage.settitle("splittabs"); stage.setwidth(700); stage.setheight(500); //setup center , right tabpanewrapper wrapper = new tabpanewrapper(orientation.horizontal, .9); tabpane centerpane = new tabpane(); centerpane.gettabs().addall(generatetab("tab 1"),generatetab("tab 2"), generatetab("tab 3"), generatetab("tab n")); tabpane rightpane = new tabpane(); rightpane.gettabs().addall(generatetab("tab 1"),generatetab("tab 2"), generatetab("tab 3"), generatetab("tab n")); splitpane.setresizablewithparent(rightpane, false); wrapper.addnodes(centerpane, rightpane); //add bottom tabpane bottompane = new tabpane(); bottompane.gettabs().addall(generatetab("tab 1"),generatetab("tab 2"), generatetab("tab 3"), generatetab("tab n")); tabpanewrapper wrapperbottom = new tabpanewrapper(orientation.vertical, .7); wrapperbottom.addnodes(wrapper.getnode(), bottompane); //add left tabpane leftpane = new tabpane(); leftpane.gettabs().addall(generatetab("tab 1"),generatetab("tab 2"), generatetab("tab 3"), generatetab("tab n")); tabpanewrapper wrapperleft = new tabpanewrapper(orientation.horizontal, .1); wrapperleft.addnodes(leftpane, wrapperbottom.getnode()); scene myscene = new scene(wrapperleft.getnode()); stage.setscene(myscene); stage.sizetoscene(); stage.show(); } public tab generatetab(string name){ tab result = new tab(name); borderpane content = new borderpane(); textarea text = new textarea(); content.setcenter(text); result.setcontent(content); return result; } public static void main(string[] args){ fxsplittabs.launch(args); } public static class tabpanewrapper{ splitpane split; public tabpanewrapper(orientation o, double splitlocation){ split = new splitpane(); //change css (uncomment if using external css) //split.getstylesheets().add("test.css"); split.setorientation(o); split.setdividerposition(0, splitlocation); } public void addnodes(final node node1, final node node2){ //add split pane split.getitems().addall(node1, node2); } public parent getnode(){ return split; } } }
i'd recommend adding ondragdetected
listener , onmousedragreleased
listener tabpanes
.
tabpanedrag drag = new tabpanedrag(); ... centerpane.setondragdetected(drag); centerpane.setonmousedragreleased(drag); ... rightpane.setondragdetected(drag); rightpane.setonmousedragreleased(drag);
in listener, can keep track of pane started drag , pane ended drag (then switch them if necessary). here's quick example (mind you, there's special cases , and kinks , such didn't bother - , findwrapper()
method returns tabpanewrapper
containing tabpane
):
public class tabpanedrag implements eventhandler<mouseevent>{ node start; node end; @override public void handle(mouseevent arg0) { if(arg0.geteventtype().equals(mouseevent.drag_detected)){ start = (node)arg0.getsource(); start.startfulldrag(); //allows events fire on nodes besides source } else if(arg0.geteventtype().equals(mousedragevent.mouse_drag_released)){ end = (node)arg0.getsource(); if(end != start){ observablelist<node> startwrapper = findwrapper(start).split.getitems(); observablelist<node> endwrapper = findwrapper(end).split.getitems(); int startindex = startwrapper.indexof(start); int endindex = endwrapper.indexof(end); // remove/add tabbedpanes new order endwrapper.remove(endindex); startwrapper.remove(startindex); startwrapper.add(startindex, end); endwrapper.add(endindex, start); } start = null; end = null; } } }
Comments
Post a Comment