Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Sizing text widgets
Sizing text widgets [message #444057] Wed, 06 October 2004 06:15 Go to next message
Howard Fore is currently offline Howard ForeFriend
Messages: 4
Registered: July 2009
Junior Member
Hi,

I'm trying to set a Text widget to be 10 lines tall. Here's my source:

GC gc = new GC (pageResponsibilitiesText);
FontMetrics fm = gc.getFontMetrics ();
int pageResponsibilitiesTextHeight = 10 * fm.getHeight();
gc.dispose ();
pageResponsibilitiesText.setSize (pageResponsibilitiesText.computeSize
(SWT.DEFAULT, pageResponsibilitiesTextHeight));
pageEditor.layout();

Problem is, when pageResponsibilitiesText gets resized, the other
widgets below the text item get overwritten. How can I resize the widget
so that the surrounding widgets move out of the way?

--
Howard Fore, me@hofo.com
Re: Sizing text widgets [message #444060 is a reply to message #444057] Wed, 06 October 2004 07:25 Go to previous messageGo to next message
Grant Slender is currently offline Grant SlenderFriend
Messages: 14
Registered: July 2009
Junior Member
It depends. What layout manager do you have on the pageEditor?

A larger snippet of your code would help understand why this happens.

Grant

"Howard Fore" <me@hofo.com> wrote in message
news:me-3FCA6D.02150306102004@eclipse.org...
> Hi,
>
> I'm trying to set a Text widget to be 10 lines tall. Here's my source:
>
> GC gc = new GC (pageResponsibilitiesText);
> FontMetrics fm = gc.getFontMetrics ();
> int pageResponsibilitiesTextHeight = 10 * fm.getHeight();
> gc.dispose ();
> pageResponsibilitiesText.setSize (pageResponsibilitiesText.computeSize
> (SWT.DEFAULT, pageResponsibilitiesTextHeight));
> pageEditor.layout();
>
> Problem is, when pageResponsibilitiesText gets resized, the other
> widgets below the text item get overwritten. How can I resize the widget
> so that the surrounding widgets move out of the way?
>
> --
> Howard Fore, me@hofo.com
Re: Sizing text widgets [message #444129 is a reply to message #444060] Thu, 07 October 2004 03:39 Go to previous message
Howard Fore is currently offline Howard ForeFriend
Messages: 4
Registered: July 2009
Junior Member
Grant Slender wrote:

> It depends. What layout manager do you have on the pageEditor?
The pageResponsibilitiesText text widget is in a composite with GridLayout
applied.

> A larger snippet of your code would help understand why this happens.
Ok. The text widget is setup in buildPageEditor, called from
createPartControl. One of the widgets setup in createPartControl is a
TabFolder. Because I could not reliably determine the width of the widget
from within createPartControl I created a listener on the tabfolder and
when the tab with the items in buildPageEditor is selected I call
setPageEditorControlsSize. This is when the pageResponsibilitiesText
widget is resized over neighboring widgets.

private void buildPageEditor() {
GridLayout pageEditorLayout = new GridLayout();
pageEditorLayout.numColumns = 3;
pageEditorLayout.makeColumnsEqualWidth = true;
pageEditor.setLayout(pageEditorLayout);

pageTitleList = new List(pageEditor,SWT.NONE);
GridData pageTitleListLayoutData = new GridData();
pageTitleListLayoutData.horizontalSpan = 1;
pageTitleListLayoutData.verticalAlignment = SWT.FILL;
pageTitleListLayoutData.horizontalAlignment = SWT.FILL;
pageTitleListLayoutData.grabExcessHorizontalSpace = true;
pageTitleListLayoutData.grabExcessVerticalSpace = true;
pageTitleList.setLayoutData(pageTitleListLayoutData);

pageTitleList.addSelectionListener(new PageTitleListListener());

Composite pageEditorComposite = new Composite(pageEditor,SWT.NONE);
GridData pageEditorCompositeLayoutData = new GridData();
pageEditorCompositeLayoutData.horizontalSpan = 2;
pageEditorCompositeLayoutData.verticalAlignment = SWT.FILL;
pageEditorCompositeLayoutData.horizontalAlignment = SWT.FILL;
pageEditorCompositeLayoutData.grabExcessHorizontalSpace = true;
pageEditorCompositeLayoutData.grabExcessVerticalSpace = true;
pageEditorComposite.setLayoutData(pageEditorCompositeLayoutD ata);

GridLayout pageEditorCompositeLayout = new GridLayout();
pageEditorCompositeLayout.numColumns = 2;
pageEditorComposite.setLayout(pageEditorCompositeLayout);

Label pageTitleLabel = new Label(pageEditorComposite,SWT.NONE);
pageTitleLabel.setText("Page title");

pageTitleText = new Text(pageEditorComposite,SWT.SINGLE|SWT.BORDER);
GridData pageTitleTextLayoutData = new GridData();
pageTitleTextLayoutData.grabExcessHorizontalSpace = true;
pageTitleTextLayoutData.horizontalAlignment = SWT.FILL;
pageTitleText.setLayoutData(pageTitleTextLayoutData);
pageTitleText.addModifyListener(
new ModifyListener() {
public void modifyText(ModifyEvent e) {
pageTitleModified = true;
}
}
);

Label pageResponsibilitiesLabel = new
Label(pageEditorComposite,SWT.NONE);
GridData pageResponsibilitiesLabelLayoutData = new GridData();
pageResponsibilitiesLabelLayoutData.verticalAlignment = SWT.TOP;
pageResponsibilitiesLabel.setLayoutData(pageResponsibilities LabelLayoutData);
pageResponsibilitiesLabel.setText("Responsibilities");

pageResponsibilitiesText = new
Text(pageEditorComposite,SWT.MULTI|SWT.WRAP|SWT.V_SCROLL|SWT .BORDER);
GridData pageResponsibilitiesTextLayoutData = new GridData();
pageResponsibilitiesTextLayoutData.grabExcessHorizontalSpace = true;
pageResponsibilitiesTextLayoutData.horizontalAlignment = SWT.FILL;
pageResponsibilitiesText.setLayoutData(pageResponsibilitiesT extLayoutData);
pageResponsibilitiesText.addModifyListener(
new ModifyListener() {
public void modifyText(ModifyEvent e) {
pageResponsibilitiesModified = true;
}
}
);

Label pageLinksLabel = new Label(pageEditorComposite,SWT.NONE);
GridData pageLinksLabelLayoutData = new GridData();
pageLinksLabelLayoutData.verticalAlignment = SWT.TOP;
pageLinksLabel.setLayoutData(pageLinksLabelLayoutData);
pageLinksLabel.setText("Exit Links");

pageLinksList = new
List(pageEditorComposite,SWT.MULTI|SWT.WRAP|SWT.V_SCROLL|SWT .BORDER);
GridData pageLinksListLayoutData = new GridData();
pageLinksListLayoutData.grabExcessHorizontalSpace = true;
pageLinksListLayoutData.horizontalAlignment = SWT.FILL;
pageLinksList.setLayoutData(pageLinksListLayoutData);

Composite fillerComposite = new Composite(pageEditorComposite,SWT.NONE);
fillerComposite.setLayoutData(new GridData());

ToolBar pageLinksToolBar = new
ToolBar(pageEditorComposite,SWT.FLAT|SWT.HORIZONTAL);
GridData pageLinksToolBarLayoutData = new GridData();
pageLinksToolBarLayoutData.grabExcessHorizontalSpace = true;
pageLinksToolBarLayoutData.horizontalAlignment = SWT.LEFT;
pageLinksToolBar.setLayoutData(pageLinksToolBarLayoutData);

ToolItem addLinkToolItem = new ToolItem(pageLinksToolBar, SWT.NONE);
addLinkToolItem.setText("Add");
ToolItem editLinkToolItem = new ToolItem(pageLinksToolBar, SWT.NONE);
editLinkToolItem.setText("Edit");
ToolItem deleteLinkToolItem = new ToolItem(pageLinksToolBar, SWT.NONE);
deleteLinkToolItem.setText("Delete");

Composite fillerCompositeBottom = new
Composite(pageEditorComposite,SWT.NONE);
GridLayout fillerCompositeBottomLayout = new GridLayout();
fillerCompositeBottomLayout.makeColumnsEqualWidth = true;
fillerCompositeBottomLayout.numColumns = 2;
fillerCompositeBottom.setLayout(fillerCompositeBottomLayout) ;

applyChangesButton = new Button(fillerCompositeBottom,SWT.PUSH);
applyChangesButton.setText("Apply");
GridData applyChangesButtonLayoutData = new GridData();
applyChangesButtonLayoutData.horizontalAlignment = SWT.FILL;
applyChangesButtonLayoutData.verticalAlignment = SWT.BOTTOM;
applyChangesButton.setLayoutData(applyChangesButtonLayoutDat a);
applyChangesButton.addSelectionListener(new
ApplyChangesButtonListener());

cancelChangesButton = new Button(fillerCompositeBottom,SWT.PUSH);
cancelChangesButton.setText("Cancel");
GridData cancelChangesButtonLayoutData = new GridData();
cancelChangesButtonLayoutData.horizontalAlignment = SWT.FILL;
cancelChangesButtonLayoutData.verticalAlignment = SWT.BOTTOM;
cancelChangesButton.setLayoutData(cancelChangesButtonLayoutD ata);
cancelChangesButton.addSelectionListener(new
CancelChangesButtonListener());

Button newPageButton = new Button (pageEditor,SWT.PUSH);
newPageButton.setText("Add new page");
newPageButton.addSelectionListener(new AddPageListener());

// Add page titles to list
// Loop over pages in DOM
NodeList pagesNodeList =
document.getDocumentElement().getElementsByTagName("page");
Element page = null;
String pageTitle = null;
for(int itr = 0; itr < pagesNodeList.getLength(); itr++) {
page = (Element) pagesNodeList.item(itr);
pageTitle =
page.getElementsByTagName("title").item(0).getFirstChild().getNodeValue();
pageTitleList.add(pageTitle);
}

cancelChangesButton.setEnabled(false);
applyChangesButton.setEnabled(false);
pageTitleText.setEnabled(false);
pageResponsibilitiesText.setEnabled(false);
pageLinksList.setEnabled(false);

pageEditor.layout(true);
}

private void setPageEditorControlsSize(){
// set responsibilities text size
GC gc = new GC (pageResponsibilitiesText);
FontMetrics fm = gc.getFontMetrics ();
int pageResponsibilitiesTextHeight = 10 * fm.getHeight();
gc.dispose ();
pageResponsibilitiesText.setSize (pageResponsibilitiesText.computeSize
(SWT.DEFAULT, pageResponsibilitiesTextHeight));
pageEditor.layout();
}
Previous Topic:How do I mimic Window/New Window
Next Topic:ToolBar and Key Binding
Goto Forum:
  


Current Time: Fri Apr 26 10:19:50 GMT 2024

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

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

Back to the top