下面列出了org.eclipse.swt.widgets.Table#setFont ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Create a column that displays data
*/
private void createTable() {
final Table table = new Table(composite, SWT.SINGLE | SWT.H_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
new TableColumn(table, SWT.LEFT);
table.setLayoutData(new RowData(150, 175));
columns.add(table);
addTableListeners(table);
if (super.getBackground() != null && super.getBackground().getRed() != 240 && super.getBackground().getGreen() != 240 && super.getBackground().getBlue() != 240) {
table.setBackground(super.getBackground());
}
table.setBackgroundImage(super.getBackgroundImage());
table.setBackgroundMode(super.getBackgroundMode());
table.setCursor(super.getCursor());
table.setFont(super.getFont());
table.setForeground(super.getForeground());
table.setMenu(super.getMenu());
table.setToolTipText(super.getToolTipText());
}
/**
* Constructs a new filtered list.
*
* @param parent
* the parent composite
* @param style
* the widget style
* @param labelProvider
* the label renderer
* @param ignoreCase
* specifies whether sorting and folding is case sensitive
* @param allowDuplicates
* specifies whether folding of duplicates is desired
* @param matchEmptyString
* specifies whether empty filter strings should filter
* everything or nothing
*/
public HistoryFilteredList(Composite parent, int style, ILabelProvider labelProvider, boolean ignoreCase,
boolean allowDuplicates, boolean matchEmptyString) {
super(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
setLayout(layout);
fList = new Table(this, style);
fList.setLayoutData(new GridData(GridData.FILL_BOTH));
fList.setFont(parent.getFont());
fList.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
fLabelProvider.dispose();
if (fUpdateJob != null) {
fUpdateJob.cancel();
}
}
});
fLabelProvider = labelProvider;
fIgnoreCase = ignoreCase;
fAllowDuplicates = allowDuplicates;
fMatchEmptyString = matchEmptyString;
}
/**
* creates the popup shell.
*
* @param selectionIndex
*/
void createPopup(final int selectionIndex) {
// create shell and table
popup = new Shell(getShell(), SWT.NO_TRIM | SWT.ON_TOP);
// create table
table = new Table(popup, SWT.SINGLE | SWT.FULL_SELECTION);
if (font != null) {
table.setFont(font);
}
if (foreground != null) {
table.setForeground(foreground);
}
if (background != null) {
table.setBackground(background);
}
// Add popup listeners
final int[] popupEvents = { SWT.Close, SWT.Paint, SWT.Deactivate, SWT.Help };
for (final int popupEvent : popupEvents) {
popup.addListener(popupEvent, listener);
}
// add table listeners
final int[] tableEvents = { SWT.MouseUp, SWT.Selection, SWT.Traverse, SWT.KeyDown, SWT.KeyUp, SWT.FocusIn,
SWT.Dispose };
for (final int tableEvent : tableEvents) {
table.addListener(tableEvent, listener);
}
// set the selection
if (selectionIndex != -1) {
table.setSelection(selectionIndex);
}
}
public static int getTableHeightHint(Table table, int rows) {
if (table.getFont().equals(JFaceResources.getDefaultFont()))
table.setFont(JFaceResources.getDialogFont());
int result = table.getItemHeight() * rows + table.getHeaderHeight();
if (table.getLinesVisible())
result += table.getGridLineWidth() * (rows - 1);
return result;
}
public static int getTableHeightHint(Table table, int rows)
{
if (table.getFont().equals(JFaceResources.getDefaultFont()))
table.setFont(JFaceResources.getDialogFont());
int result = table.getItemHeight() * rows + table.getHeaderHeight();
if (table.getLinesVisible())
result += table.getGridLineWidth() * (rows - 1);
return result;
}
/**
* @param parent
*/
private void createTaskTableArea(Composite parent)
{
fTasksTableViewer = new TableViewer(parent, SWT.BORDER | SWT.SINGLE);
Table table = fTasksTableViewer.getTable();
table.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
table.setHeaderVisible(true);
table.setLinesVisible(true);
table.setFont(parent.getFont());
TableColumn tagNameColumn = new TableColumn(table, SWT.NONE);
tagNameColumn.setText(Messages.TasksPreferencePage_TagNameColumnHeader);
tagNameColumn.setWidth(100);
TableColumn tagPriorityColumn = new TableColumn(table, SWT.NONE);
tagPriorityColumn.setText(Messages.TasksPreferencePage_PriorityColumnHeader);
tagPriorityColumn.setWidth(100);
fTasksTableViewer.setContentProvider(ArrayContentProvider.getInstance());
fTasksTableViewer.setLabelProvider(new TaskLabelProvider());
fTasksTableViewer.setComparator(new ViewerComparator());
fTasksTableViewer.setInput(getTaskTags());
fTasksTableViewer.addSelectionChangedListener(new ISelectionChangedListener()
{
public void selectionChanged(SelectionChangedEvent event)
{
// Enable/disable buttons
updateButtonStates();
}
});
createTaskButtons(parent);
}
private Control createTable(Composite parent) {
Composite c= new Composite(parent, SWT.NONE);
GridLayout gl= new GridLayout();
gl.numColumns= 2;
gl.marginWidth= 0;
gl.marginHeight= 0;
c.setLayout(gl);
fTable= new Table(c, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION | SWT.HIDE_SELECTION | SWT.BORDER);
fTable.setFont(parent.getFont());
GridData tableGD= new GridData(GridData.FILL_BOTH);
tableGD.heightHint= SWTUtil.getTableHeightHint(fTable, ROW_COUNT);
//tableGD.widthHint= 40;
fTable.setLayoutData(tableGD);
fTable.setLinesVisible(true);
TableLayout layout= new TableLayout();
fTable.setLayout(layout);
fTable.setHeaderVisible(true);
ColumnLayoutData[] columnLayoutData= new ColumnLayoutData[SIZE];
columnLayoutData[STATE_PROP]= new ColumnPixelData(18, false, true);
columnLayoutData[KEY_PROP]= new ColumnWeightData(40, true);
columnLayoutData[VAL_PROP]= new ColumnWeightData(40, true);
for (int i= 0; i < fgTitles.length; i++) {
TableColumn tc= new TableColumn(fTable, SWT.NONE, i);
tc.setText(fgTitles[i]);
layout.addColumnData(columnLayoutData[i]);
tc.setResizable(columnLayoutData[i].resizable);
}
createButtonComposite(c);
return c;
}
@Override
protected TableViewer createTableViewer(Composite parent) {
Table table= new Table(parent, SWT.CHECK | getListStyle());
table.setFont(parent.getFont());
CheckboxTableViewer tableViewer= new CheckboxTableViewer(table);
tableViewer.addCheckStateListener(new ICheckStateListener() {
public void checkStateChanged(CheckStateChangedEvent e) {
doCheckStateChanged(e);
}
});
return tableViewer;
}
public static int getTableHeightHint(Table table, int rows) {
if (table.getFont().equals(JFaceResources.getDefaultFont()))
table.setFont(JFaceResources.getDialogFont());
int result= table.getItemHeight() * rows + table.getHeaderHeight();
if (table.getLinesVisible())
result+= table.getGridLineWidth() * (rows - 1);
return result;
}
void createPopup( Object[] items, int selectionIndex )
{
// create shell and list
popup = new Shell( getShell( ), SWT.NO_TRIM | SWT.ON_TOP );
table = new Table( popup, SWT.SINGLE
| SWT.V_SCROLL
| SWT.FULL_SELECTION );
new TableColumn( table, SWT.LEFT );
if ( font != null )
table.setFont( font );
if ( foreground != null )
table.setForeground( foreground );
if ( background != null )
table.setBackground( background );
label.setBackground( table.getBackground( ) );
label.setForeground( table.getForeground( ) );
label.setFont( table.getFont( ) );
int[] popupEvents = {
SWT.Close, SWT.Paint, SWT.Deactivate
};
for ( int i = 0; i < popupEvents.length; i++ )
popup.addListener( popupEvents[i], listener );
int[] tableEvents = {
SWT.MouseUp,
SWT.Selection,
SWT.Traverse,
SWT.KeyDown,
SWT.KeyUp,
SWT.FocusIn,
SWT.FocusOut,
SWT.Dispose
};
for ( int i = 0; i < tableEvents.length; i++ )
table.addListener( tableEvents[i], listener );
}
public static int getTableHeightHint(Table table, int rows) {
if (table.getFont().equals(JFaceResources.getDefaultFont())) {
table.setFont(JFaceResources.getDialogFont());
}
int result = table.getItemHeight() * rows + table.getHeaderHeight();
if (table.getLinesVisible()) {
result += table.getGridLineWidth() * (rows - 1);
}
return result;
}
/**
* creates the popup shell.
* @param selectionIndex
*/
void createPopup(int selectionIndex) {
// create shell and table
popup = new Shell(getShell(), SWT.NO_TRIM | SWT.ON_TOP);
// create table
table = new Table(popup, SWT.SINGLE | SWT.FULL_SELECTION);
if (font != null)
table.setFont(font);
if (foreground != null)
table.setForeground(foreground);
if (background != null)
table.setBackground(background);
// Add popup listeners
int[] popupEvents = { SWT.Close, SWT.Paint, SWT.Deactivate };
for (int i = 0; i < popupEvents.length; i++) {
popup.addListener(popupEvents[i], listener);
}
// add table listeners
int[] tableEvents = { SWT.MouseUp, SWT.Selection, SWT.Traverse, SWT.KeyDown, SWT.KeyUp, SWT.FocusIn,
SWT.Dispose };
for (int i = 0; i < tableEvents.length; i++) {
table.addListener(tableEvents[i], listener);
}
// set the selection
if (selectionIndex != -1) {
table.setSelection(selectionIndex);
}
}
protected Control createDialogArea(Composite container){
Composite parent = (Composite) super.createDialogArea(container);
createMessageArea(parent);
fTableViewer = new TableViewer(parent, getTableStyle());
fTableViewer.setContentProvider(ArrayContentProvider.getInstance());
addColumns();
setComparator();
fTableViewer.setInput(this);
fTableViewer.addDoubleClickListener(new IDoubleClickListener() {
public void doubleClick(DoubleClickEvent event){
if (fAddCancelButton) {
okPressed();
}
}
});
List initialSelection = getInitialElementSelections();
if (initialSelection != null) {
fTableViewer.setSelection(new StructuredSelection(initialSelection));
}
GridData gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = convertHeightInCharsToPixels(heightInChars);
gd.widthHint = convertWidthInCharsToPixels(widthInChars);
Table table = fTableViewer.getTable();
table.setLayoutData(gd);
table.setFont(container.getFont());
table.setHeaderVisible(true);
IQuery<IOrder> query = CoreModelServiceHolder.get().getQuery(IOrder.class);
fTableViewer.setInput(query.execute());
return parent;
}
protected TableViewer createTableViewer(Composite parent) {
Table table = new Table(parent, getListStyle());
table.setFont(parent.getFont());
return new TableViewer(table);
}
/**
* createUserAgentTable
*
* @param parent
*/
protected void createUserAgentTable(Composite parent)
{
Label label = new Label(parent, SWT.WRAP);
label.setText(Messages.UserAgentPreferencePage_Select_User_Agents);
label.setLayoutData(GridDataFactory.fillDefaults().span(2, 0).grab(true, true).create());
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(GridLayoutFactory.fillDefaults().create());
composite.setLayoutData(GridDataFactory.fillDefaults().span(2, 0).hint(400, 120).grab(true, true).create());
Table table = new Table(composite, SWT.CHECK | SWT.BORDER | SWT.SINGLE);
table.setFont(parent.getFont());
categoryViewer = new CheckboxTableViewer(table);
categoryViewer.getControl().setFont(parent.getFont());
categoryViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
categoryViewer.setContentProvider(ArrayContentProvider.getInstance());
CategoryLabelProvider categoryLabelProvider = new CategoryLabelProvider(true);
categoryViewer.setLabelProvider(categoryLabelProvider);
categoryViewer.setComparator(new ViewerComparator()
{
@Override
public int compare(Viewer viewer, Object e1, Object e2)
{
if (e1 instanceof IUserAgent && e2 instanceof IUserAgent)
{
IUserAgent ua1 = (IUserAgent) e1;
IUserAgent ua2 = (IUserAgent) e2;
String uaName1 = StringUtil.getStringValue(ua1.getName());
String uaName2 = StringUtil.getStringValue(ua2.getName());
return uaName1.compareToIgnoreCase(uaName2);
}
return super.compare(viewer, e1, e2);
}
});
categoryViewer.setInput(UserAgentManager.getInstance().getAllUserAgents());
}
protected TableViewer createTableViewer(Composite parent) {
Table table= new Table(parent, getListStyle());
table.setFont(parent.getFont());
return new TableViewer(table);
}
/**
* creates the popup shell.
* @param selectionIndex
*/
void createPopup(int selectionIndex) {
// create shell and table
popup = new Shell(getShell(), SWT.NO_TRIM | SWT.ON_TOP);
// set style
int style = getStyle();
int tableStyle = SWT.SINGLE | SWT.V_SCROLL;
if ((style & SWT.FLAT) != 0)
tableStyle |= SWT.FLAT;
if ((style & SWT.RIGHT_TO_LEFT) != 0)
tableStyle |= SWT.RIGHT_TO_LEFT;
if ((style & SWT.LEFT_TO_RIGHT) != 0)
tableStyle |= SWT.LEFT_TO_RIGHT;
// create table
table = new Table(popup, SWT.SINGLE | SWT.FULL_SELECTION);
if (font != null)
table.setFont(font);
if (foreground != null)
table.setForeground(foreground);
if (background != null)
table.setBackground(background);
// Add popup listeners
int[] popupEvents = { SWT.Close, SWT.Paint, SWT.Deactivate, SWT.Help };
for (int i = 0; i < popupEvents.length; i++) {
popup.addListener(popupEvents[i], listener);
}
// add table listeners
int[] tableEvents = { SWT.MouseMove, SWT.MouseUp, SWT.Selection, SWT.Traverse, SWT.KeyDown, SWT.KeyUp,
SWT.FocusIn, SWT.Dispose };
for (int i = 0; i < tableEvents.length; i++) {
table.addListener(tableEvents[i], listener);
}
// set the selection
if (selectionIndex != -1) {
table.setSelection(selectionIndex);
}
}
/**
* creates the popup shell.
* @param selectionIndex
*/
void createPopup(int selectionIndex) {
// create shell and table
popup = new Shell(getShell(), SWT.NO_TRIM | SWT.ON_TOP);
// set style
int style = getStyle();
int tableStyle = SWT.SINGLE | SWT.V_SCROLL;
if ((style & SWT.FLAT) != 0)
tableStyle |= SWT.FLAT;
if ((style & SWT.RIGHT_TO_LEFT) != 0)
tableStyle |= SWT.RIGHT_TO_LEFT;
if ((style & SWT.LEFT_TO_RIGHT) != 0)
tableStyle |= SWT.LEFT_TO_RIGHT;
// create table
table = new Table(popup, SWT.SINGLE | SWT.FULL_SELECTION);
if (font != null)
table.setFont(font);
if (foreground != null)
table.setForeground(foreground);
if (background != null)
table.setBackground(background);
// Add popup listeners
int[] popupEvents = { SWT.Close, SWT.Paint, SWT.Deactivate, SWT.Help };
for (int i = 0; i < popupEvents.length; i++) {
popup.addListener(popupEvents[i], listener);
}
// add table listeners
int[] tableEvents = { SWT.MouseMove, SWT.MouseUp, SWT.Selection, SWT.Traverse, SWT.KeyDown, SWT.KeyUp,
SWT.FocusIn, SWT.Dispose };
for (int i = 0; i < tableEvents.length; i++) {
table.addListener(tableEvents[i], listener);
}
// set the selection
if (selectionIndex != -1) {
table.setSelection(selectionIndex);
}
}
/**
* Sets the font that the receiver will use to paint textual information to the
* font specified by the argument, or to the default font for that kind of
* control if the argument is null.
*
* @param font the new font (or null)
*
* @exception IllegalArgumentException
* <ul>
* <li>ERROR_INVALID_ARGUMENT - if the argument has been
* disposed</li>
* </ul>
* @exception SWTException
* <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been
* disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
* thread that created the receiver</li>
* </ul>
* @see org.eclipse.swt.widgets.Control#setFont(org.eclipse.swt.graphics.Font)
*/
@Override
public void setFont(final Font font) {
super.setFont(font);
for (final Table column : columns) {
column.setFont(font);
}
}