Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java GUI 设计  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 急:如何在tableviewer中固定前两列?
terrence





发贴: 3
积分: 0
于 2006-06-22 09:30 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
如何在tableviewer中固定前两列?
后面的在横向拖动中,前两列不变,其他的随拖动而变,请各位达人支招,万分感谢!
急急急



作者 Re:急:如何在tableviewer中固定前两列? [Re:terrence]
terrence





发贴: 3
积分: 0
于 2006-06-24 09:52 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
高手呢?怎么没人能给解答下?


作者 Re:急:如何在tableviewer中固定前两列? [Re:terrence]
liuzhenke15





发贴: 45
积分: 0
于 2006-06-24 10:50 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
在Swing开发指南中有一章节专门讲这个。


作者 Re:急:如何在tableviewer中固定前两列? [Re:terrence]
terrence





发贴: 3
积分: 0
于 2006-06-26 17:11 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
swing下没有tableviewer

俺要swt的



作者 Re:急:如何在tableviewer中固定前两列? [Re:terrence]
lilimalin





发贴: 1
积分: 0
于 2006-09-07 14:53 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.custom.TableEditor;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.internal.win32.OS;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
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 dbtable{
public static void main (String [] args) {
int rowCount = 40;
int columnCount = 14;
final Display display = new Display ();
Shell shell = new Shell (display);
shell.setLayout(new FillLayout());



Composite parent = new Composite(shell, SWT.BORDER);
final GridLayout gridLayout = new GridLayout(2,false);
gridLayout.marginWidth = gridLayout.marginHeight = gridLayout.horizontalSpacing = 0;
// gridLayout.numColumns = 2;
gridLayout.marginWidth = 0;
parent.setLayout(gridLayout);

final Composite composite = new Composite(parent, SWT.NONE);
final GridLayout gridLayout_1 = new GridLayout();
gridLayout_1.horizontalSpacing = 0;
gridLayout_1.marginWidth = 0;
gridLayout_1.marginHeight = 0;
composite.setLayout(gridLayout_1);
final GridData gridData = new GridData(SWT.LEFT, SWT.FILL, false, true);
gridData.widthHint = 26;
composite.setLayoutData(gridData);



final Composite composite_1 = new Composite(parent, SWT.NONE);
composite_1.setLayout(new FillLayout());
composite_1.setLayoutData(new GridData(GridData.FILL_BOTH));



final Table leftTable = new Table(composite, SWT.MULTI | SWT.FULL_SELECTION);
final GridData gridData_1 = new GridData(SWT.LEFT, SWT.FILL, false, true);
gridData_1.widthHint = 25;
leftTable.setLayoutData(gridData_1);
leftTable.setHeaderVisible(true);
leftTable.setLinesVisible(true);


final Table rightTable = new Table(composite_1, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
rightTable.setHeaderVisible(true);
rightTable.setLinesVisible(true);

// Create columns
TableColumn column0 = new TableColumn(leftTable, SWT.NONE);
column0.setText("");
column0.setWidth(0);
TableColumn column1 = new TableColumn(leftTable, SWT.NONE);
column1.setResizable(false);
column1.setText("");
column1.setWidth(25);

for (int i = 0; i < columnCount; i++) {


TableColumn column = new TableColumn(rightTable, SWT.NONE);

column.setText("Value "+i);
column.setWidth(200);

}
// Create rows
TableEditor te[] = new TableEditor[rowCount];
Image image = new Image(display, 1, 17);

for (int i = 0; i < rowCount; i++) {
TableItem item = new TableItem(leftTable, SWT.NONE);
item.setChecked(true);
te = new TableEditor(leftTable);
te.horizontalAlignment = SWT.LEFT;
te.grabHorizontal = true;

final CLabel lbl = new CLabel(leftTable, SWT.SHADOW_OUT);
lbl.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
lbl.setAlignment(SWT.CENTER);
lbl.setEnabled(false);
te.setEditor(lbl, item, 1);
item.setImage(image);
// "/icons/01.gif").getImageData()));
//ImageDescriptor.createFromURL();
//loadImage();
item = new TableItem(rightTable, SWT.NONE);
item.setImage(image);
for (int j = 0; j < columnCount; j++) {
item.setText(j, "Item "+i+" value @ "+j);
}
}




// Make selection the same in both tables
leftTable.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
rightTable.setSelection(leftTable.getSelectionIndices());
}
});
// On Windows, the selection is gray if the table does not have focus.
// To make both tables appear in focus, draw teh selection background here.
// This part only works on version 3.2 or later.
Listener eraseListener = new Listener() {
public void handleEvent(Event event) {
if((event.detail & SWT.SELECTED) != 0) {
GC gc = event.gc;
Rectangle rect = event.getBounds();
gc.setForeground(display.getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT));
gc.setBackground(display.getSystemColor(SWT.COLOR_LIST_SELECTION));
gc.fillRectangle(rect);
event.detail &= ~SWT.SELECTED;
}
}
};


Label spacer = new Label(parent, SWT.NONE);
GridData spacerData = new GridData();



leftTable.addListener(SWT.EraseItem, eraseListener);
// Make vertical scrollbars scroll together
ScrollBar vBarLeft = leftTable.getVerticalBar();
vBarLeft.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
rightTable.setTopIndex(leftTable.getTopIndex());
}
});
rightTable.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
leftTable.setSelection(rightTable.getSelectionIndices());
}
});
rightTable.addListener(SWT.EraseItem, eraseListener);
ScrollBar vBarRight = rightTable.getVerticalBar();
vBarRight.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
leftTable.setTopIndex(rightTable.getTopIndex());
}
});
// Horizontal bar on second table takes up a little extra space.
// To keep vertical scroll bars in sink, force table1 to end above
// horizontal scrollbar
ScrollBar hBarRight = rightTable.getHorizontalBar();
spacerData.heightHint = hBarRight.getSize().y;
spacer.setVisible(false);
parent.setBackground(leftTable.getBackground());

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




flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923