[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.technology.albireo] Re: For Starters...


Cklewis wrote:
I just wanted to drop my thoughts and say I think this will be a great and very useful project. I'm glad there's always people out there trying to make things easier for the rest of us, in this case the SWT/Swing integration.

It's really helpful to know of your interest and what you are working on, so thanks for that.


...

I downloaded the examples, but none of them are runnable when I tried them. It would have been helpful to actually have code for a runnable program that embedded a swing component in it, even if it was a small snippet.

Sorry about that. You didn't mention if you are writing an Eclipse RCP application or just a standalone SWT application. Below is a snippet that implements an RCP view with a simple embedded Swing JTable, using the code included with the article. If you're writing a standalone SWT application, you should be able to take just the code from createPartControl() and added it to a shell or some other composite. Once you get it running, you should also be able to replace the JTable with another component of your choice. Make sure you take a look at the javadoc as well. The sample code still has some issues, as you can see from some of the other posts in this newsgroup.


public class JTableView extends ViewPart {

    private EmbeddedSwingComposite embeddedComposite;

    public void createPartControl(Composite parent) {
        embeddedComposite = new EmbeddedSwingComposite(parent, 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;
            }
        };
        embeddedComposite.populate();
    }

    public void setFocus() {
        embeddedComposite.setFocus();
    }

}