Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Table ScrollBar missing in GridLayout and Rowlayout(ScrollBar does not appear in tables for GridLayout. and RowLayout while it appears for FillLayout)
Table ScrollBar missing in GridLayout and Rowlayout [message #497094] Thu, 12 November 2009 13:59 Go to next message
Sajit  is currently offline Sajit Friend
Messages: 6
Registered: October 2009
Junior Member
Hi,

The scroll bar does not appear for the tables in the code below for GridLayout and RowLayout. However it appears for FillLayout.

I want it to appear for GridLayout.

The code is as follows:

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.ScrollBar;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;


public class MatrixView {

public MatrixView() {
}

public static void main (String [] args) {
Display display = new Display ();
Shell shell = new Shell (display);
// uncommenting line below will make scroll bar appear
//shell.setLayout(new FillLayout());

/*RowLayout rowLayout = new RowLayout();
rowLayout.wrap = false;
shell.setLayout(rowLayout);*/

GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 2;
gridLayout.marginWidth = 1;
shell.setLayout(gridLayout);

final ScrolledComposite sc1 = new ScrolledComposite (shell,
SWT.H_SCROLL
| SWT.V_SCROLL);
final ScrolledComposite sc2 = new ScrolledComposite (shell,
SWT.H_SCROLL
| SWT.V_SCROLL);

Table table1 = new Table(sc1,SWT.SINGLE);
table1.setHeaderVisible(false);
table1.setLinesVisible(true);

TableColumn col1 = new TableColumn(table1,SWT.LEFT);
col1.setWidth(200);
TableColumn col2 = new TableColumn(table1,SWT.LEFT);
col2.setWidth(60);

for (int i = 0; i < 60; i++) {
TableItem item1 = new TableItem(table1,0);
item1.setText(new String[]{"Line " + i,"b"});
}

Table table2 = new Table(sc2,SWT.SINGLE);
table2.setHeaderVisible(false);
table2.setLinesVisible(true);

for (int i = 0; i < 10; i++) {
TableColumn col21 = new TableColumn(table2,SWT.LEFT);
col21.setWidth(80);
}

for (int i = 0; i < 60; i++) {
TableItem item1 = new TableItem(table2,0);
item1.setText(new String[]{"Line "+i,"c"});
}

sc1.setContent(table1);
table1.pack();

sc2.setContent(table2);
table2.pack();


System.out.println("Show");

shell.setSize (500, 500);
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}

}

Any help will be appreciated.


Thanks,
Sajit


Re: Table ScrollBar missing in GridLayout and Rowlayout [message #497998 is a reply to message #497094] Fri, 13 November 2009 16:08 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
Hi Sajit,

Here's your snippet with a few changes to show scrollbars with GridLayout:

public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
// uncommenting line below will make scroll bar appear
// shell.setLayout(new FillLayout());

/*
* RowLayout rowLayout = new RowLayout(); rowLayout.wrap = false;
* shell.setLayout(rowLayout);
*/

GridLayout gridLayout = new GridLayout(2, true);
gridLayout.marginWidth = 1;
shell.setLayout(gridLayout);

final ScrolledComposite sc1 = new ScrolledComposite(shell, SWT.H_SCROLL
| SWT.V_SCROLL | SWT.BORDER);
final ScrolledComposite sc2 = new ScrolledComposite(shell, SWT.H_SCROLL
| SWT.V_SCROLL | SWT.BORDER);

Table table1 = new Table(sc1, SWT.SINGLE);
table1.setHeaderVisible(false);
table1.setLinesVisible(true);

TableColumn col1 = new TableColumn(table1, SWT.LEFT);
col1.setWidth(200);
TableColumn col2 = new TableColumn(table1, SWT.LEFT);
col2.setWidth(60);

for (int i = 0; i < 60; i++) {
TableItem item1 = new TableItem(table1, 0);
item1.setText(new String[] { "Line " + i, "b" });
}

Table table2 = new Table(sc2, SWT.SINGLE);
table2.setHeaderVisible(false);
table2.setLinesVisible(true);

for (int i = 0; i < 10; i++) {
TableColumn col21 = new TableColumn(table2, SWT.LEFT);
col21.setWidth(80);
}

for (int i = 0; i < 60; i++) {
TableItem item1 = new TableItem(table2, 0);
item1.setText(new String[] { "Line " + i, "c" });
}
sc1.setLayoutData(new GridData(GridData.FILL_BOTH));
sc2.setLayoutData(new GridData(GridData.FILL_BOTH));
sc1.setContent(table1);
sc2.setContent(table2);
table1.pack();
table2.pack();
shell.setSize(500, 500);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}

Grant


"Sajit" <catchpiscean@rediffmail.com> wrote in message
news:hdh4ba$qmh$1@build.eclipse.org...
> Hi,
>
> The scroll bar does not appear for the tables in the code below for
GridLayout and RowLayout. However it appears for FillLayout.
>
> I want it to appear for GridLayout.
>
> The code is as follows:
>
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.custom.ScrolledComposite;
> import org.eclipse.swt.events.SelectionAdapter;
> import org.eclipse.swt.events.SelectionEvent;
> import org.eclipse.swt.events.SelectionListener;
> import org.eclipse.swt.graphics.Point;
> import org.eclipse.swt.layout.FillLayout;
> import org.eclipse.swt.layout.GridLayout;
> import org.eclipse.swt.layout.RowData;
> import org.eclipse.swt.layout.RowLayout;
> import org.eclipse.swt.widgets.Button;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.ScrollBar;
> import org.eclipse.swt.widgets.Shell;
> import org.eclipse.swt.widgets.Table;
> import org.eclipse.swt.widgets.TableColumn;
> import org.eclipse.swt.widgets.TableItem;
>
>
> public class MatrixView {
>
> public MatrixView() {
> }
>
> public static void main (String [] args) {
> Display display = new Display ();
> Shell shell = new Shell (display);
> // uncommenting line below will make scroll bar appear
> //shell.setLayout(new FillLayout());
>
> /*RowLayout rowLayout = new RowLayout();
> rowLayout.wrap = false;
> shell.setLayout(rowLayout);*/
>
> GridLayout gridLayout = new GridLayout();
> gridLayout.numColumns = 2;
> gridLayout.marginWidth = 1;
> shell.setLayout(gridLayout);
>
> final ScrolledComposite sc1 = new ScrolledComposite (shell,
> SWT.H_SCROLL
> | SWT.V_SCROLL);
> final ScrolledComposite sc2 = new ScrolledComposite (shell,
> SWT.H_SCROLL
> | SWT.V_SCROLL);
>
> Table table1 = new Table(sc1,SWT.SINGLE);
> table1.setHeaderVisible(false);
> table1.setLinesVisible(true);
>
> TableColumn col1 = new TableColumn(table1,SWT.LEFT);
> col1.setWidth(200);
> TableColumn col2 = new TableColumn(table1,SWT.LEFT);
> col2.setWidth(60);
>
> for (int i = 0; i < 60; i++) {
> TableItem item1 = new TableItem(table1,0);
> item1.setText(new String[]{"Line " + i,"b"});
> }
>
> Table table2 = new Table(sc2,SWT.SINGLE);
> table2.setHeaderVisible(false);
> table2.setLinesVisible(true);
>
> for (int i = 0; i < 10; i++) {
> TableColumn col21 = new TableColumn(table2,SWT.LEFT);
> col21.setWidth(80);
> }
>
> for (int i = 0; i < 60; i++) {
> TableItem item1 = new TableItem(table2,0);
> item1.setText(new String[]{"Line "+i,"c"});
> }
>
> sc1.setContent(table1);
> table1.pack();
>
> sc2.setContent(table2);
> table2.pack();
>
>
> System.out.println("Show");
>
> shell.setSize (500, 500);
> shell.open ();
> while (!shell.isDisposed ()) {
> if (!display.readAndDispatch ()) display.sleep ();
> }
> display.dispose ();
> }
>
> }
>
> Any help will be appreciated.
>
>
> Thanks,
> Sajit
>
>
>
Re: Table ScrollBar missing in GridLayout and Rowlayout [message #838246 is a reply to message #497998] Fri, 06 April 2012 19:49 Go to previous message
Dirk Hoffmann is currently offline Dirk HoffmannFriend
Messages: 1
Registered: April 2012
Junior Member
    // parent code her ...
    {
         final ScrolledComposite scrolledComposite = new ScrolledComposite(shell, SWT.BORDER | SWT.V_SCROLL);
         {
              composite = new Composite(scrolledComposite, SWT.NONE);
              composite.setBounds(0, 0, 300, 200);
              composite.setBackground(ResourceManager.getColor(SWT.COLOR_CYAN));
              scrolledComposite.setContent(composite);
              {
                 final Button button = new Button(composite, SWT.NONE);
                 button.setBounds(150, 115, 60, 35);
                 button.setText("button");
              }
         }
    }
    // and AFTER! everything had been set, we do a:
    composite.setSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
Previous Topic:How to handle unsupported data type when calling java script function using SWT Browser
Next Topic:Dynamic 32-64 bit loading
Goto Forum:
  


Current Time: Thu Mar 28 23:26:20 GMT 2024

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

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

Back to the top