Results 1 to 1 of 1
- 05-15-2008, 04:52 PM #1
Member
- Join Date
- May 2008
- Posts
- 1
- Rep Power
- 0
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.
Java 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.
Java 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(); } }
Similar Threads
-
Java Control Panel not saving changes when I press OK
By RebelScum in forum New To JavaReplies: 0Last Post: 03-21-2008, 04:22 PM -
How to control robots and other devices
By francojava in forum Advanced JavaReplies: 0Last Post: 01-24-2008, 04:03 PM -
X11.Toolkit logging out of control
By gjsalazar in forum AWT / SwingReplies: 0Last Post: 11-20-2007, 11:42 PM -
Control Structure Question
By ibanez270dx in forum New To JavaReplies: 1Last Post: 11-12-2007, 10:10 PM -
Linux Bluetooth Remote Control 0.4
By levent in forum Java SoftwareReplies: 0Last Post: 05-11-2007, 09:54 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks