Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
re: [platform-swt-dev] Resizing issues

Hello,
In fact, the idea of the pack() method is to compact your component so that it uses the minimum size it can to display its contents. So if you use the pack method, the shell size will be changed since that's what pack() is suposed to do. Try deleting the shell.pack() line.
By the way, doubts like that one related to the use of SWT are better be sent to:
eclipse.platform.swt-newsgroup
You will get faster answers.

Hugo


De: "Juriy Bura" <juriy.bura@xxxxxxxxx>
Enviado: sexta-feira, 8 de setembro de 2006 04:14
Para: platform-swt-dev@xxxxxxxxxxx
Assunto: [platform-swt-dev] Resizing issues


I've started using SWT two days ago, so I beg your pardon if my question is too simple.

I've got a problem with setting the size to my components. I'm trying to make a text window to display logs of my application. I want the window to be 500x150. But using methods like:

shell.setBounds(30, 30, 500, 150);

or

myTextArea.setBounds(30, 30, 500, 150);

doesn't do the job.

I've tried to debug a little, and I've found that size negotiation happens in the shell.pack () method. It sets the window size to 112x48 (I guess, this is the defaults).

I've looked at the javadoc for this method:

 * Causes the receiver to be resized to its preferred size.
 * For a composite, this involves computing the preferred size
 * from its layout, if there is one.
 
Is there another way to set a preferred size???
 
Then I've trying to get the idea of size computation, but soon got tired of endless debug. As I've seen, shell size is calculated from a layout size, layout size - from it's components size.
My StyledText tried to calculate it's size from it's renderer... or something.... and no one tried to look at the bounds that i've set!

Another thing: when i'm trying to set bounds in a separate loop - all works fine. Below is my code. What am I doing wrong???

package ua.net.lab.logger;

import org.eclipse.jface.resource
.FontRegistry;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.graphics.FontData ;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class Test {

    private Display display;

    private Shell shell;

    public StyledText myTextArea;
    

    public Test() {
        init();
        System.out.println("After Init " + shell.getBounds());
        shell.pack();
        System.out.println("Afetr Pack " + shell.getBounds());
        
        shell.open();
        
        
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                // If no more entries in event queue
                display.sleep();
            }
        }
        display.dispose();
    }

    private void init() {
        display = new Display();
        shell = new Shell(display);
         shell.setLayout(new FillLayout());

        FontRegistry fontRegistry = new FontRegistry(display);

        fontRegistry.put("log-message", new FontData[] { new FontData(
                "Courier New", 10, SWT.NORMAL) });

        myTextArea = new StyledText(shell, SWT.BORDER | SWT.V_SCROLL);
        myTextArea.setFont(fontRegistry.get("log-message"));

        myTextArea.setBounds(30, 30, 500, 150);
        shell.setBounds(30, 30, 500, 150);
        
    }

    public static void main(String[] args) {
        new Test();
    }
}

I'm sorry, if answer is obvious... BTW my SWT version is 3.232


Back to the top