Skip to main content



      Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Table with scrollbar
Table with scrollbar [message #632757] Thu, 14 October 2010 03:44 Go to next message
Eclipse UserFriend
Hi everybody, i'm having trouble with scrollbars in table.
The problem is that my table is very large (more than 1000 rows) and i want the user to be able to scroll it. owever every solution i tried did not work. My question is: how can i get the following code to work and to display scrollbars?
Thanks in advance
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;

public class SchedaClienteShell {
	private String user=null;  //  @jve:decl-index=0:
	private Shell shell=null;  //  @jve:decl-index=0:visual-constraint="10,-44"
	private Display display=null;
	private Composite datiCliente=null;
	private TabFolder clienteTabFolder=null;
	private Composite appuntamentiEffettuatiTab = null;
	private Composite appuntamentiProgrammatiTab = null;
	private Composite comunicazioniTab = null;;
	private Table appuntamentiEffettuatiTable=null;
	private Table appuntamentiProgrammatiTable;
	private Table comunicazioniTable;
	
	public void initialize(String user){
		this.user=user;
		display = new Display();
		shell = new Shell(display);
		shell.setText("Scheda cliente");
		shell.setMaximized(true);
		shell.setLayout(new RowLayout(SWT.HORIZONTAL));
		this.initializePannelloDatiCliente();
		this.initializeTabs();
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
	}
	
	///////////////////////////////////////////////////////////////////////////////////////////////
	//Sezione tabs

	private void initializeTabs() {
		clienteTabFolder=new TabFolder(shell,SWT.NONE);
		clienteTabFolder.setLayout(new GridLayout());
		//clienteTabFolder.setLayoutData(new RowData(SWT.FILL,SWT.NONE));
		createAppuntamentiEffettuatiTab();
        createAppuntamentiProgrammatiTab();
        createComunicazioniTab();
        createGruppoTab();
        createAgenteTab();
		TabItem tabItem = new TabItem(clienteTabFolder, SWT.NONE);
        tabItem.setControl(appuntamentiEffettuatiTab);
        tabItem.setText("Appuntamenti effettuati");
        TabItem tabItem1 = new TabItem(clienteTabFolder, SWT.NONE);
        tabItem1.setControl(appuntamentiProgrammatiTab);
        tabItem1.setText("Appuntamenti programmati");
        TabItem tabItem2 = new TabItem(clienteTabFolder, SWT.NONE);
        tabItem2.setText("Appuntamenti programmati");
        tabItem2.setControl(comunicazioniTab);
        tabItem2.setText("Comunicazioni");
        TabItem tabItem3 = new TabItem(clienteTabFolder, SWT.NONE);
        clienteTabFolder.pack();
	}
	
	private void createAppuntamentiEffettuatiTab() {
		appuntamentiEffettuatiTab = new Composite(clienteTabFolder, SWT.NONE);
		appuntamentiEffettuatiTab.setLayout(new GridLayout());
		appuntamentiEffettuatiTable = new Table(appuntamentiEffettuatiTab, SWT.MULTI | SWT.CHECK | SWT.FULL_SELECTION | SWT.BORDER);
		appuntamentiEffettuatiTable.setLayoutData(new GridData(SWT.NONE, SWT.FILL, true, true));
		appuntamentiEffettuatiTable.setHeaderVisible(true);
		appuntamentiEffettuatiTable.setLinesVisible(true);
		TableColumn[] colonne = new TableColumn[8];
		colonne[0]=new TableColumn(appuntamentiEffettuatiTable, SWT.NONE);
		colonne[0].setText("Data");
		colonne[1]=new TableColumn(appuntamentiEffettuatiTable, SWT.NONE);
		colonne[1].setText("Ora");
		colonne[2]=new TableColumn(appuntamentiEffettuatiTable, SWT.NONE);
		colonne[2].setText("Durata");
		colonne[3]=new TableColumn(appuntamentiEffettuatiTable, SWT.NONE);
		colonne[3].setText("Indirizzo");
		colonne[4]=new TableColumn(appuntamentiEffettuatiTable, SWT.NONE);
		colonne[4].setText("Agente di riferimento");
		colonne[5]=new TableColumn(appuntamentiEffettuatiTable, SWT.NONE);
		colonne[5].setText("Agente incaricato");
		colonne[6]=new TableColumn(appuntamentiEffettuatiTable, SWT.NONE);
		colonne[6].setText("Descrizione");
		colonne[7]=new TableColumn(appuntamentiEffettuatiTable, SWT.NONE);
		colonne[7].setText("Motivo");
		fillTable(appuntamentiEffettuatiTable);
	}
	
	private void fillTable(Table table){
		table.setRedraw(false);
		//Riempire con i dati pescati dal DB
		for (int i=0; i<100; i++){
			TableItem item=new TableItem(table,SWT.NONE);
			for (int j=0; j<table.getColumnCount(); j++){
				item.setText(j, "item "+i);
			}
		}
		for (int j=0; j<table.getColumnCount(); j++){
			table.getColumns()[j].pack();
		}
		table.setRedraw(true);
	}
	
	private void createAppuntamentiProgrammatiTab() {
		appuntamentiProgrammatiTab = new Composite(clienteTabFolder, SWT.NONE);
		appuntamentiProgrammatiTab.setLayout(new GridLayout());
		appuntamentiProgrammatiTable = new Table(appuntamentiProgrammatiTab, SWT.MULTI | SWT.CHECK | SWT.FULL_SELECTION | SWT.BORDER);
		appuntamentiProgrammatiTable.setLayoutData(new GridData(SWT.NONE, SWT.FILL, true, true));
		appuntamentiProgrammatiTable.setHeaderVisible(true);
		appuntamentiProgrammatiTable.setLinesVisible(true);
		TableColumn[] colonne = new TableColumn[7];
		colonne[0]=new TableColumn(appuntamentiProgrammatiTable, SWT.NONE);
		colonne[0].setText("Data");
		colonne[1]=new TableColumn(appuntamentiProgrammatiTable, SWT.NONE);
		colonne[1].setText("Ora");
		colonne[2]=new TableColumn(appuntamentiProgrammatiTable, SWT.NONE);
		colonne[2].setText("Termine ultimo");
		colonne[3]=new TableColumn(appuntamentiProgrammatiTable, SWT.NONE);
		colonne[3].setText("Indirizzo");
		colonne[4]=new TableColumn(appuntamentiProgrammatiTable, SWT.NONE);
		colonne[4].setText("Agente di riferimento");
		colonne[5]=new TableColumn(appuntamentiProgrammatiTable, SWT.NONE);
		colonne[5].setText("Motivo");
		colonne[6]=new TableColumn(appuntamentiProgrammatiTable, SWT.NONE);
		colonne[6].setText("Stato");
		fillTable(appuntamentiProgrammatiTable);
	}

private void fillTable(Table table){
		table.setRedraw(false);
		//Riempire con i dati pescati dal DB
		for (int i=0; i<100; i++){
			TableItem item=new TableItem(table,SWT.NONE);
			for (int j=0; j<table.getColumnCount(); j++){
				item.setText(j, "item "+i);
			}
		}
		for (int j=0; j<table.getColumnCount(); j++){
			table.getColumns()[j].pack();
		}
		table.setRedraw(true);
	}

	//Other tabs similar to the first one

	//////////////////////////////////////////////////////////////////////////////////////////////////
	
	///////////////////////////////////////////////////////////////////////////////////////////////////////////////
	//Sezione pannello Dati Cliente
	
	private void initializePannelloDatiCliente() {
		if(datiCliente==null){
			datiCliente=new DatiClienteComposite(shell, SWT.NONE);
		}
	}

[Updated on: Thu, 14 October 2010 16:50] by Moderator

Re: Table with scrollbar [message #633572 is a reply to message #632757] Mon, 18 October 2010 08:53 Go to previous message
Eclipse UserFriend
Hi,

It looks like this is happening due to RowLayout. Can you use either FillLayout or GridLayout on the shell instead of RowLayout, the scrollbar appears as expected.
Previous Topic:SWT Browser does not navigate links
Next Topic:Simple SWT Table
Goto Forum:
  


Current Time: Tue Jul 22 19:39:51 EDT 2025

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

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

Back to the top