开发者

Eclipse plugin development: Vertically scrolling table?

开发者 https://www.devze.com 2023-01-31 08:39 出处:网络
I\'m trying to create a vertically scrolling table within a dialog, without success.When I create the table, it auto-expands to whatever height it needs to be regardless of screen size/resolution.Lots

I'm trying to create a vertically scrolling table within a dialog, without success. When I create the table, it auto-expands to whatever height it needs to be regardless of screen size/resolution. Lots of data creates a table that extends well below the bottom of the screen.

My code goes something like this (not verbatim, may be a type-o or two):

final Table table = new Table(parent, SWT.SINGLE | 
  SWT.FULL_SELECTION | SWT.SCROLL_LINE | borderStyle | orientation );
table.setHeaderVisible(true);
table.setLinesVisible(true);

TableViewer tableView = new TableViewer(table);

// code yanked to set up the columns (movable == false, 
// resiable == true, with set text, widths, and toolTipText)

tableView.setContentProvider(new ArrayContentProvider());
// BeanLabelPr开发者_如何学Pythonovider's getColumnText returns the beanDescriptor's
// getReadMethod.invoke().toString()
tableView.setLabelProvider(new BeanLableProvider(MyClass.class));
tableView.setInput(anArrayOfMyClass);

All this code lives in my dialog class's createDialogArea().

At any rate, I've tried the following:

  1. treeView.setItemCount() trims the data, it doesn't limit the amount of data displayed.
  2. table.getVerticalBar() returns a valid ScrollBar, and that scrollbar.getVisible() == true;?! Really? Prove it. Didn't think so. setVisible(true) does nothing.
  3. table.setBounds()? Nope. Even after I call layout() and/or redraw().
  4. The above was done within createDialogArea(). If I call setBounds() within MyDialog.initializeBounds() it shrinks the table and adds scrollbars (gasp!), but the dialog doesn't resize. Calling table.getParent().layout(true) resizes the table, not the dialog. Augh!
  5. In initBounds, I have the following code:

    Shell shell = getShell();
    shell.setBounds(foo, bar, baz qux);
    myTable.setBounds(foo, bar, baz-fudgeX, qux-fudgeY);
    myTable.getVerticalBar().setVisible(true); // see, it wasn't null!
    // this line doesn't seem to have any effect, I can comment it out and have
    // the same apparent result.
    shell.layout(true);
    // If I call shell.pack() the table snaps back to its original size (huge).
    

Without the call to pack(), the okay/cancel buttons are clipped off the bottom of the dialog. With it, the entire exercise is a moot point.

Why do I get the feeling I'm missing something Really Basic that'll make me want to smack my forehead when someone else points it out?


What layout do you use for your Shell? Most layouts simply ask the controls for their preferred size, during a call of layout(). The preferred size of your Table is the size, where all rows can be displayed. If there's no more constraints, the layout resizes the Shell to that preferred size, which is not what you want.

To prevent this, you'll need to set a height hint for your layout on your Table. An example for that is this snippet. If you remove the line

data.heightHint = 200;

the resulting Shell is way too high.

0

精彩评论

暂无评论...
验证码 换一张
取 消