java - SWT Create Two StyledText That Scroll In Tandem -
i have create 2 styledtext
scroll in tandem , getting code creating same using scrolledcomposites
. have limitation of using styledtext
because, using other purpose well. want create same thing link here using styledtext
.
i tried same code replacing scrolledcomposites
styledtext
din't allowed me setorigin(x , y)
.
you can use methods styledtext#sethorizontalpixel()
, styledtext#settoppixel()
(and respecrive get
methods) , set positions:
public static void main(string[] args) { final display display = new display(); final shell shell = new shell(display); shell.setlayout(new filllayout()); styledtext 1 = new styledtext(shell, swt.border | swt.v_scroll | swt.h_scroll); styledtext 2 = new styledtext(shell, swt.border | swt.v_scroll | swt.h_scroll); one.setalwaysshowscrollbars(true); two.setalwaysshowscrollbars(true); one.settext("scroll scroll scroll\ndown down down\nto to\nsee see see\nthe the\nstyled styled styled\ntexts texts texts\nscroll scroll scroll\nin in in\ntandem tandem tandem"); two.settext("scroll scroll scroll\ndown down down\nto to\nsee see see\nthe the\nstyled styled styled\ntexts texts texts\nscroll scroll scroll\nin in in\ntandem tandem tandem"); handleverticalscrolling(one, two); handlehorizontalscrolling(one, two); shell.pack(); shell.setsize(200, 100); shell.open(); while (!shell.isdisposed()) { if (!display.readanddispatch()) display.sleep(); } display.dispose(); } private static void handlehorizontalscrolling(styledtext one, styledtext two) { scrollbar hone = one.gethorizontalbar(); scrollbar htwo = two.gethorizontalbar(); hone.addlistener(swt.selection, e -> { int x = one.gethorizontalpixel(); two.sethorizontalpixel(x); }); htwo.addlistener(swt.selection, e -> { int x = two.gethorizontalpixel(); one.sethorizontalpixel(x); }); } private static void handleverticalscrolling(styledtext one, styledtext two) { scrollbar vone = one.getverticalbar(); scrollbar vtwo = two.getverticalbar(); vone.addlistener(swt.selection, e -> { int y = one.gettoppixel(); two.settoppixel(y); }); vtwo.addlistener(swt.selection, e -> { int y = two.gettoppixel(); one.settoppixel(y); }); }
Comments
Post a Comment