java - Open new tab in swt browser after button click -
i used swt
browser. opened page , there button
verify browser have option open new browser window. standard swt
browser have problem it. above how button defined.
<button class="btn btn-action btn-slim size-w-90pct" data-e2e="opendealerbtn" ng-if="igdefaultrowcontroller.account.ispdsupported" ng-class="{'btn-disabled': igdefaultrowcontroller.shoulddisableopenplatformbutton}" ng-disabled="igdefaultrowcontroller.shoulddisableopenplatformbutton" ng-click="igdefaultrowcontroller.opendealer()" ig-click-tracking="puredealbtn-cfd" id="opendealerbutton-xq7ji"> <span class="btn-label" ig-i18n="" key="accountoverview.opendealer"><span ng-bind-html="value">open classic platform</span></span> </button>
- [solved!] how expand
swt
browser open more 1 tab ?- i used
tabfolder
more tabs.
- i used
- it possible catch url after click on button , open in new swt browser tab ?
swt uses 1 of browsers available on operating system , embeds main "view" of browser (the bit displays html) in application. mean, however, doesn't come fancy stuff tabs.
as discovered yourself, can around using tabfolder
.
the question is: how know when tab should opened. code (adopted snippet270) should this:
public static void main(string[] args) { display display = new display(); shell shell = new shell(display); shell.settext("main window"); shell.setlayout(new filllayout()); final browser browser; try { browser = new browser(shell, swt.none); } catch (swterror e) { system.out.println("could not instantiate browser: " + e.getmessage()); display.dispose(); return; } initialize(display, browser); shell.open(); browser.seturl("http://www.w3schools.com/html/tryit.asp?filename=tryhtml_links_target"); while (!shell.isdisposed()) { if (!display.readanddispatch()) display.sleep(); } display.dispose(); } /* register windowevent listeners */ static void initialize(final display display, browser browser) { browser.addopenwindowlistener(e -> { shell shell = new shell(display); shell.settext("new window"); shell.setlayout(new filllayout()); browser browser1 = new browser(shell, swt.none); initialize(display, browser1); e.browser = browser1; }); browser.addvisibilitywindowlistener(new visibilitywindowlistener() { @override public void hide(windowevent e) { browser browser = (browser) e.widget; shell shell = browser.getshell(); shell.setvisible(false); } @override public void show(windowevent e) { browser browser = (browser) e.widget; final shell shell = browser.getshell(); if (e.location != null) shell.setlocation(e.location); if (e.size != null) { point size = e.size; shell.setsize(shell.computesize(size.x, size.y)); } shell.open(); } }); browser.addclosewindowlistener(e -> { browser browser1 = (browser) e.widget; shell shell = browser1.getshell(); shell.close(); }); }
this open link in new shell
new browser
. can change this, creates new tab , adds new browser new tab.
edit
here's working example using tabfolder
:
public static void main(string[] args) { display display = new display(); shell shell = new shell(display); shell.settext("main window"); shell.setlayout(new filllayout()); tabfolder tabfolder = new tabfolder(shell, swt.border); addnewbrowser(tabfolder, "<a href='http://www.google.co.uk' target='_blank'>click here!</a>"); shell.open(); while (!shell.isdisposed()) { if (!display.readanddispatch()) display.sleep(); } display.dispose(); } private static browser addnewbrowser(tabfolder folder, string html) { tabitem item = new tabitem(folder, swt.none); composite c = new composite(folder, swt.none); item.setcontrol(c); c.setlayout(new filllayout()); browser browser = new browser(c, swt.none); if (html != null) { browser.settext(html); item.settext("original tab"); } else { item.settext("new tab"); } browser.addopenwindowlistener(e -> { e.browser = addnewbrowser(folder, null); }); browser.addvisibilitywindowlistener(new visibilitywindowlistener() { @override public void hide(windowevent e) { browser browser = (browser) e.widget; shell shell = browser.getshell(); shell.setvisible(false); } @override public void show(windowevent e) { browser browser = (browser) e.widget; final shell shell = browser.getshell(); if (e.location != null) shell.setlocation(e.location); if (e.size != null) { point size = e.size; shell.setsize(shell.computesize(size.x, size.y)); } shell.open(); } }); browser.addclosewindowlistener(e -> { browser browser1 = (browser) e.widget; shell shell = browser1.getshell(); shell.close(); }); folder.setselection(item); return browser; }
Comments
Post a Comment