[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: Multi-line Text with constant number of visible rows...

Veronika,

Many thanks... it now works great.  It's not immediately obvious from the
docs that Layouts and setSize() or setBounds() methods are mutually
exclusive.


"Veronika Irvine" <veronika_irvine@xxxxxxx> wrote in message
news:d04vaf$or2$1@xxxxxxxxxxxxxxxxxx
> You probably have a Layout on the shell and this is overriding the result
of
> payloadWindow.setSize(payloadWindow.computeSize(width, height));  You can
> not mix a Layout with calls to setSize() or setBounds() - you must choose
> one or the other.  Below is an example using GridLayout that sets the size
> of the Text widget:
>
> public static void main (String [] args) {
>         Display display = new Display ();
>         Shell shell = new Shell (display);
>         shell.setLayout(new GridLayout(2, false));
>         Text payloadWindow = new Text(shell, SWT.BORDER | SWT.MULTI
> |SWT.V_SCROLL | SWT.H_SCROLL);
>         GC gc = new GC(payloadWindow);
>         FontMetrics fm = gc.getFontMetrics ();
>         gc.dispose ();
>         int cols = 80;
>         int rows = 10;
>         int width = cols * fm.getAverageCharWidth();
>         int height = rows * fm.getHeight();
>         GridData data = new GridData();
>         data.widthHint = width;
>         data.heightHint = height;
>         payloadWindow.setLayoutData(data);
>         Button b = new Button(shell, SWT.PUSH);
>         b.setText("Button");
>         shell.pack();
>         shell.open ();
>         while (!shell.isDisposed ()) {
>                 if (!display.readAndDispatch ()) display.sleep ();
>         }
>         display.dispose ();
> }
>
> "Martin Smithson" <msmiths@xxxxxxxxxx> wrote in message
> news:d04nif$ed3$1@xxxxxxxxxxxxxxxxxx
> > Hi,
> >
> > I am trying to emulate the behaviour that can be achieved in SWING by
> > using
> > a JTextArea and a JScrollPane together, as follows:
> >
> >    JTextArea payloadWindow = new JTextArea();
> >    payloadWindow.setRows(10);
> >    payloadWindow.setColumns(80);
> >
> >    JScrollPane payloadWindowScrollPane = new JScrollPane();
> >    payloadWindowScrollPane.setViewportView(payloadWindow);
> >    payloadWindowScrollPane.setMinimumSize(new Dimension(400, 400));
> >
> > However, I cannot find any way to tell a Text control to size itself to
a
> > given number of displayable rows and columns.  I have code similar to
the
> > following:
> >
> >    int cols = 80;
> >    int rows = 10;
> >    GC gc = new GC(payloadWindow);
> >    FontMetrics fm = gc.getFontMetrics ();
> >    int width = cols * fm.getAverageCharWidth();
> >    int height = rows * fm.getHeight ();
> >    gc.dispose ();
> >    payloadWindow.setSize(payloadWindow.computeSize(width, height));
> >
> > The problem with this is that the Text control is initially empty.
> > Therefore, when I invoke pack() on my dialog, the control gets resized
> > smaller.  Also, if add extra lines of text (>10) and then pack() is
> > invoked
> > on the dialog, my Text control gets resized larger then 10 rows.
> >
> > The behaviour that I would like to see is to always have 10 rows by 80
> > columns, even when the Text control is empty or contains a large amount
of
> > text, and I would like to have scroll bars displayed for the Text
control
> > when they are required, i.e., when more than 10 rows are entered or a
line
> > longer than 80 characters is entered.
> >
> > Any ideas?
> >
> > P.S.  I have tried to place the Text control inside a ScrolledPane, but
> > still cannot achieve the desired results.
> >
> >
>
>