Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » SWT Browser in an Eclipse Form, problem.
SWT Browser in an Eclipse Form, problem. [message #312745] Mon, 19 February 2007 11:02 Go to next message
Eclipse UserFriend
Originally posted by: mlong1958.gmail.com

I have an SWT Browser in an Eclipse Form using TableWrapLayout. My
problem is that the Browser does not extend to the bottom of the view.
It is only about 100 px tall. I can set the Browser's size but
unfortunately it does not stretch when the view is resized. I like the
flat look and the TableWrapLayout is very handy.

I have some buttons, label, and text box above the browser.

I've looked high and low but cannot find an event for when the view is
resized. A quick look of this forum indicates that this is an internal
action? That would be a very handy thing to have right now.

Anyone have any ideas?

I'm about to give up on using an Eclipse form for this view. The
relevant code is below.



public class BrowserView extends ViewPart {
private Composite parent;
private FormToolkit toolkit;
private Form form;
private int VIEW_NUM_COLS = 6;
Browser browser;
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
IWorkbenchPage page = window.getActivePage();
IWorkspace workspace = ResourcesPlugin.getWorkspace();

public BrowserView() {}

public void createPartControl(Composite parent) {
this.parent = parent;
toolkit = new FormToolkit(parent.getDisplay());
form = toolkit.createForm(parent);
form.setText("Welcome.");
TableWrapLayout layout = new TableWrapLayout();
form.getBody().setLayout(layout);
layout.numColumns = VIEW_NUM_COLS;
TableWrapData td = new TableWrapData(TableWrapData.FILL);
td.valign = TableWrapData.MIDDLE;
Button goButton =
toolkit.createButton(form.getBody(), "Go", SWT.PUSH);
goButton.setLayoutData(td);
td = new TableWrapData(TableWrapData.FILL);
td.valign = TableWrapData.MIDDLE;
Button backButton =
toolkit.createButton(form.getBody(), "Back", SWT.PUSH);
backButton.setLayoutData(td);
td = new TableWrapData(TableWrapData.FILL);
td.valign = TableWrapData.MIDDLE;
Button stopButton =
toolkit.createButton(form.getBody(), "Stop", SWT.PUSH);
stopButton.setLayoutData(td);
td = new TableWrapData(TableWrapData.FILL);
td.valign = TableWrapData.MIDDLE;
Label urlLabel = toolkit.createLabel(form.getBody(), "URL");
urlLabel.setLayoutData(td);
td = new TableWrapData(TableWrapData.FILL_GRAB);
td.valign = TableWrapData.MIDDLE;
final Text urlText = toolkit.createText(form.getBody(), "");
urlText.setLayoutData(td);
td = new TableWrapData(TableWrapData.FILL_GRAB);
td.colspan = VIEW_NUM_COLS;

try{
browser = new Browser(form.getBody(), SWT.BORDER);
browser.setSize(600, 400);
browser.setLayoutData(td);
Listener buttonListener = new Listener() {
public void handleEvent(Event event) {
if(event.widget instanceof Button){
String string = ((Button) event.widget).getText();
if(string.equals("Back"))
browser.back();
if(string.equals("Stop"))
browser.stop();
if(string.equals("Go"))
browser.setUrl(urlText.getText());
}
}
};
goButton.addListener(SWT.Selection, buttonListener);
backButton.addListener(SWT.Selection, buttonListener);
stopButton.addListener(SWT.Selection, buttonListener);
browser.setUrl("www.google.com");

urlText.addListener(SWT.DefaultSelection, new Listener() {
public void handleEvent(Event e) {
browser.setUrl(urlText.getText());
}
});

}
// Whoa, the Browser couldn't be created!
catch(SWTError e){
Text errorText =
new Text(form.getBody(), SWT.MULTI | SWT.READ_ONLY);
errorText.setText("Browser widget cannot be instantiated." +
" The exact error is:\n\n" + e);
parent.layout(true);
return;
}// catch(SWTError)
}// createPartControl(Composite parent)

/**
* @see org.eclipse.ui.part.WorkbenchPart#setFocus()
*/
public void setFocus() {
form.setFocus();
}

/**
* Disposes the FormToolkit (toolkit) object.
*/
public void dispose() {
toolkit.dispose();
super.dispose();
}
Re: SWT Browser in an Eclipse Form, problem. RESOLVED (sort of) [message #312777 is a reply to message #312745] Tue, 20 February 2007 04:22 Go to previous message
Eclipse UserFriend
Originally posted by: mlong1958.gmail.com

Ok, I guess this just isn't an instance where Eclipse forms were meant
to be used. I changed to GridLayout and everything works fine.

The Form object body does not automatically extend to the bottom of the
view so the Browser object has to be a fixed size.

Michael Long wrote:
> I have an SWT Browser in an Eclipse Form using TableWrapLayout. My
> problem is that the Browser does not extend to the bottom of the view.
> It is only about 100 px tall. I can set the Browser's size but
> unfortunately it does not stretch when the view is resized. I like the
> flat look and the TableWrapLayout is very handy.
>
> I have some buttons, label, and text box above the browser.
>
> I've looked high and low but cannot find an event for when the view is
> resized. A quick look of this forum indicates that this is an internal
> action? That would be a very handy thing to have right now.
>
> Anyone have any ideas?
>
> I'm about to give up on using an Eclipse form for this view. The
> relevant code is below.
>
>
>
> public class BrowserView extends ViewPart {
> private Composite parent;
> private FormToolkit toolkit;
> private Form form;
> private int VIEW_NUM_COLS = 6;
> Browser browser;
> IWorkbench workbench = PlatformUI.getWorkbench();
> IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
> IWorkbenchPage page = window.getActivePage();
> IWorkspace workspace = ResourcesPlugin.getWorkspace();
>
> public BrowserView() {}
>
> public void createPartControl(Composite parent) {
> this.parent = parent;
> toolkit = new FormToolkit(parent.getDisplay());
> form = toolkit.createForm(parent);
> form.setText("Welcome.");
> TableWrapLayout layout = new TableWrapLayout();
> form.getBody().setLayout(layout);
> layout.numColumns = VIEW_NUM_COLS;
> TableWrapData td = new TableWrapData(TableWrapData.FILL);
> td.valign = TableWrapData.MIDDLE;
> Button goButton =
> toolkit.createButton(form.getBody(), "Go", SWT.PUSH);
> goButton.setLayoutData(td);
> td = new TableWrapData(TableWrapData.FILL);
> td.valign = TableWrapData.MIDDLE;
> Button backButton =
> toolkit.createButton(form.getBody(), "Back", SWT.PUSH);
> backButton.setLayoutData(td);
> td = new TableWrapData(TableWrapData.FILL);
> td.valign = TableWrapData.MIDDLE;
> Button stopButton =
> toolkit.createButton(form.getBody(), "Stop", SWT.PUSH);
> stopButton.setLayoutData(td);
> td = new TableWrapData(TableWrapData.FILL);
> td.valign = TableWrapData.MIDDLE;
> Label urlLabel = toolkit.createLabel(form.getBody(), "URL");
> urlLabel.setLayoutData(td);
> td = new TableWrapData(TableWrapData.FILL_GRAB);
> td.valign = TableWrapData.MIDDLE;
> final Text urlText = toolkit.createText(form.getBody(), "");
> urlText.setLayoutData(td);
> td = new TableWrapData(TableWrapData.FILL_GRAB);
> td.colspan = VIEW_NUM_COLS;
>
> try{
> browser = new Browser(form.getBody(), SWT.BORDER);
> browser.setSize(600, 400);
> browser.setLayoutData(td);
> Listener buttonListener = new Listener() {
> public void handleEvent(Event event) {
> if(event.widget instanceof Button){
> String string = ((Button) event.widget).getText();
> if(string.equals("Back"))
> browser.back();
> if(string.equals("Stop"))
> browser.stop();
> if(string.equals("Go"))
> browser.setUrl(urlText.getText());
> }
> }
> };
> goButton.addListener(SWT.Selection, buttonListener);
> backButton.addListener(SWT.Selection, buttonListener);
> stopButton.addListener(SWT.Selection, buttonListener);
> browser.setUrl("www.google.com");
>
> urlText.addListener(SWT.DefaultSelection, new Listener() {
> public void handleEvent(Event e) {
> browser.setUrl(urlText.getText());
> }
> });
>
> }
> // Whoa, the Browser couldn't be created!
> catch(SWTError e){
> Text errorText =
> new Text(form.getBody(), SWT.MULTI | SWT.READ_ONLY);
> errorText.setText("Browser widget cannot be instantiated." +
> " The exact error is:\n\n" + e);
> parent.layout(true);
> return;
> }// catch(SWTError)
> }// createPartControl(Composite parent)
>
> /**
> * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
> */
> public void setFocus() {
> form.setFocus();
> }
>
> /**
> * Disposes the FormToolkit (toolkit) object.
> */
> public void dispose() {
> toolkit.dispose();
> super.dispose();
> }
Previous Topic:Commands and Handlers used with Menu actions
Next Topic:modifying jar files on build path requires remove-readd
Goto Forum:
  


Current Time: Thu Aug 29 01:27:33 GMT 2024

Powered by FUDForum. Page generated in 0.03099 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top