[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.technology.albireo] Re: Advice on getting started?

Cklewis wrote:

I went off of your snippet you posted (the one with the JTables) and also your Eclipse article and i'm apparently doing something wrong still.

From the code you posted, it looks like you are trying to embed the JTable in a SashForm. I took the standard SWT snippet for SashForm and modified it to make one of its children a JTable, with the help of the source code from my article. Here's the whole thing. I hope it helps.


/*******************************************************************************
 * Copyright (c) 2000, 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation

*******************************************************************************/
package org.eclipse.swt.snippets;

/*
 * SashForm example snippet: create a sash form with three children
 *
 * For a list of all SWT example snippets see
 * http://www.eclipse.org/swt/snippets/
 */
import java.util.Vector;

import javax.swing.JComponent;
import javax.swing.JScrollPane;
import javax.swing.JTable;

import org.eclipse.swt.*;
import org.eclipse.swt.custom.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

import swingintegration.example.EmbeddedSwingComposite;

public class Snippet109 {

public static void main (String [] args) {
	final Display display = new Display ();
	Shell shell = new Shell(display);
	shell.setLayout (new FillLayout());

	SashForm form = new SashForm(shell,SWT.HORIZONTAL);
	form.setLayout(new FillLayout());
	
	Composite child1 = new Composite(form,SWT.NONE);
	child1.setLayout(new FillLayout());
	new Label(child1,SWT.NONE).setText("Label in pane 1");
	
	Composite child2 = new Composite(form,SWT.NONE);
	child2.setLayout(new FillLayout());
	new Button(child2,SWT.PUSH).setText("Button in pane2");

	// Composite child3 = new Composite(form,SWT.NONE);
    // child3.setLayout(new FillLayout());
    // new Label(child3,SWT.PUSH).setText("Label in pane3");

EmbeddedSwingComposite child3 = new EmbeddedSwingComposite(form, SWT.NONE) {
protected JComponent createSwingComponent() {
/* Creating components */
int nrows = 1000, ncolumns = 10;
Vector rows = new Vector();
for (int i = 0; i < nrows; i++) {
Vector row = new Vector();
for (int j = 0; j < ncolumns; j++) {
row.addElement("Item " + i + "-" + j);
}
rows.addElement(row);
}
Vector columns = new Vector();
for (int i = 0; i < ncolumns; i++) {
columns.addElement("Column " + i);
}
JTable table = new JTable(rows, columns);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
table.createDefaultColumnsFromModel();


            JScrollPane scrollPane = new JScrollPane(table);

            return scrollPane;
        }
    };
    child3.populate();
	
	
	form.setWeights(new int[] {30,40,30});
	shell.open ();
	while (!shell.isDisposed ()) {
		if (!display.readAndDispatch ()) display.sleep ();
	}
	display.dispose ();
}
}