Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-15-2008, 05:52 PM
Member
 
Join Date: May 2008
Posts: 1
thebillybobjr is on a distinguished road
control app width based on certain control
Hi,

I'm fairly new to using layouts, and I have scoured plenty of tutorials, but I cannot find anything that handles this situation.

*Note. I do not want to use setBounds, I want to be decided based on the controls text length.

I am just trying to create a simple application that has a label and a button (button will change to another control, but works the same for the example). I want the application window width to be determined by the width of the button (set to grab as much as it needs horizontally). I want the label to be above the button, and to wrap its text, but not to grab horizontally past what the button needs.

Code:
------------------------------------------------| | -------------------------------------------- | | | This is the label text that will wrap | | | | because of the app width .... | | | -------------------------------------------- | | -------------------------------------------- | | | Button: want this 2 determine width .... | | | -------------------------------------------- | -------------------------------------------------


I have tried to tell the composite to grab vertical, as well as the shell. I also have tried using the widthhint by setting it to 0. This works initially. But the form height will be set as if the label was 1 line and cut off part of the button height, until you resize the window, then it will extend to include the text and the button.

I have this code to try to do it.


Code:
import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; public class TestApp { public static void main(String[] args) throws Exception { Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new GridLayout()); shell.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); Composite c = new Composite(shell, SWT.NONE); c.setLayout(new GridLayout()); c.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); Label label = new Label(c, SWT.WRAP | SWT.READ_ONLY); label.setText("This is some really long text that will fill up the label. " + "This text will be longer than the button text, (doesn't have to be a button). " + "So I hope this is enough text to make it longer than the button."); GridData glabel = new GridData(SWT.FILL, SWT.FILL, false, false);// , true, false); glabel.widthHint = 0; // this way it will be excluded from computing the app width label.setLayoutData(glabel); Button button = new Button(c, SWT.PUSH); button.setText("This is some really long text that will determine the button width " + "that I want to control the page starting width by." + "I sure hope it works. "); c.pack(); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java Control Panel not saving changes when I press OK RebelScum New To Java 0 03-21-2008 05:22 PM
How to control robots and other devices francojava Advanced Java 0 01-24-2008 05:03 PM
X11.Toolkit logging out of control gjsalazar AWT / Swing 0 11-21-2007 12:42 AM
Control Structure Question ibanez270dx New To Java 1 11-12-2007 11:10 PM
Linux Bluetooth Remote Control 0.4 levent Java Announcements 0 05-11-2007 10:54 PM


All times are GMT +3. The time now is 12:06 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org