List of usage examples for org.eclipse.swt.widgets Label setForeground
public void setForeground(Color color)
From source file:FontDialogColorFontData.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Font Chooser"); shell.setLayout(new GridLayout(2, false)); final Label fontLabel = new Label(shell, SWT.NONE); fontLabel.setText("The selected font"); Button button = new Button(shell, SWT.PUSH); button.setText("Font..."); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { Font font = null;// w ww . j a v a 2s .c o m Color color = null; FontDialog dlg = new FontDialog(shell); if (font != null) dlg.setFontList(fontLabel.getFont().getFontData()); if (color != null) dlg.setRGB(color.getRGB()); if (dlg.open() != null) { if (font != null) font.dispose(); if (color != null) color.dispose(); font = new Font(shell.getDisplay(), dlg.getFontList()); fontLabel.setFont(font); color = new Color(shell.getDisplay(), dlg.getRGB()); fontLabel.setForeground(color); shell.pack(); if (font != null) font.dispose(); if (color != null) color.dispose(); } } }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:MainClass.java
public static void main(String[] a) { Display display = new Display(); // Create the main window final Shell shell = new Shell(display); shell.setLayout(new GridLayout(2, false)); final Label fontLabel = new Label(shell, SWT.NONE); fontLabel.setText("The selected font"); Button button = new Button(shell, SWT.PUSH); button.setText("Font..."); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { // Create the color-change dialog FontDialog dlg = new FontDialog(shell); Font font = null;//ww w . j a v a2 s. c o m Color color = null; if (font != null) dlg.setFontList(fontLabel.getFont().getFontData()); if (color != null) dlg.setRGB(color.getRGB()); if (dlg.open() != null) { if (font != null) font.dispose(); if (color != null) color.dispose(); font = new Font(shell.getDisplay(), dlg.getFontList()); fontLabel.setFont(font); color = new Color(shell.getDisplay(), dlg.getRGB()); fontLabel.setForeground(color); shell.pack(); } } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:Snippet125.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new FillLayout()); final Table table = new Table(shell, SWT.BORDER); for (int i = 0; i < 20; i++) { TableItem item = new TableItem(table, SWT.NONE); item.setText("item " + i); }// www .j a v a 2 s.co m // Disable native tooltip table.setToolTipText(""); // Implement a "fake" tooltip final Listener labelListener = new Listener() { public void handleEvent(Event event) { Label label = (Label) event.widget; Shell shell = label.getShell(); switch (event.type) { case SWT.MouseDown: Event e = new Event(); e.item = (TableItem) label.getData("_TABLEITEM"); // Assuming table is single select, set the selection as if // the mouse down event went through to the table table.setSelection(new TableItem[] { (TableItem) e.item }); table.notifyListeners(SWT.Selection, e); // fall through case SWT.MouseExit: shell.dispose(); break; } } }; Listener tableListener = new Listener() { Shell tip = null; Label label = null; public void handleEvent(Event event) { switch (event.type) { case SWT.Dispose: case SWT.KeyDown: case SWT.MouseMove: { if (tip == null) break; tip.dispose(); tip = null; label = null; break; } case SWT.MouseHover: { TableItem item = table.getItem(new Point(event.x, event.y)); if (item != null) { if (tip != null && !tip.isDisposed()) tip.dispose(); tip = new Shell(shell, SWT.ON_TOP | SWT.TOOL); tip.setLayout(new FillLayout()); label = new Label(tip, SWT.NONE); label.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND)); label.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); label.setData("_TABLEITEM", item); label.setText("tooltip " + item.getText()); label.addListener(SWT.MouseExit, labelListener); label.addListener(SWT.MouseDown, labelListener); Point size = tip.computeSize(SWT.DEFAULT, SWT.DEFAULT); Rectangle rect = item.getBounds(0); Point pt = table.toDisplay(rect.x, rect.y); tip.setBounds(pt.x, pt.y, size.x, size.y); tip.setVisible(true); } } } } }; table.addListener(SWT.Dispose, tableListener); table.addListener(SWT.KeyDown, tableListener); table.addListener(SWT.MouseMove, tableListener); table.addListener(SWT.MouseHover, tableListener); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet125.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 125"); shell.setLayout(new FillLayout()); final Table table = new Table(shell, SWT.BORDER); for (int i = 0; i < 20; i++) { TableItem item = new TableItem(table, SWT.NONE); item.setText("item " + i); }/*w w w .j a v a 2 s. co m*/ // Disable native tooltip table.setToolTipText(""); // Implement a "fake" tooltip final Listener labelListener = event -> { Label label = (Label) event.widget; Shell shell1 = label.getShell(); switch (event.type) { case SWT.MouseDown: Event e = new Event(); e.item = (TableItem) label.getData("_TABLEITEM"); // Assuming table is single select, set the selection as if // the mouse down event went through to the table table.setSelection(new TableItem[] { (TableItem) e.item }); table.notifyListeners(SWT.Selection, e); shell1.dispose(); table.setFocus(); break; case SWT.MouseExit: shell1.dispose(); break; } }; Listener tableListener = new Listener() { Shell tip = null; Label label = null; @Override public void handleEvent(Event event) { switch (event.type) { case SWT.Dispose: case SWT.KeyDown: case SWT.MouseMove: { if (tip == null) break; tip.dispose(); tip = null; label = null; break; } case SWT.MouseHover: { TableItem item = table.getItem(new Point(event.x, event.y)); if (item != null) { if (tip != null && !tip.isDisposed()) tip.dispose(); tip = new Shell(shell, SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL); tip.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); FillLayout layout = new FillLayout(); layout.marginWidth = 2; tip.setLayout(layout); label = new Label(tip, SWT.NONE); label.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND)); label.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); label.setData("_TABLEITEM", item); label.setText(item.getText()); label.addListener(SWT.MouseExit, labelListener); label.addListener(SWT.MouseDown, labelListener); Point size = tip.computeSize(SWT.DEFAULT, SWT.DEFAULT); Rectangle rect = item.getBounds(0); Point pt = table.toDisplay(rect.x, rect.y); tip.setBounds(pt.x, pt.y, size.x, size.y); tip.setVisible(true); } } } } }; table.addListener(SWT.Dispose, tableListener); table.addListener(SWT.KeyDown, tableListener); table.addListener(SWT.MouseMove, tableListener); table.addListener(SWT.MouseHover, tableListener); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:TooltipTableItem.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new FillLayout()); final Table table = new Table(shell, SWT.BORDER); for (int i = 0; i < 20; i++) { TableItem item = new TableItem(table, SWT.NONE); item.setText("item " + i); }/*from w ww.j a va2 s .com*/ // Disable native tooltip table.setToolTipText(""); // Implement a "fake" tooltip final Listener labelListener = new Listener() { public void handleEvent(Event event) { Label label = (Label) event.widget; Shell shell = label.getShell(); switch (event.type) { case SWT.MouseDown: Event e = new Event(); e.item = (TableItem) label.getData("_TABLEITEM"); // Assuming table is single select, set the selection as if // the mouse down event went through to the table table.setSelection(new TableItem[] { (TableItem) e.item }); table.notifyListeners(SWT.Selection, e); shell.dispose(); table.setFocus(); break; case SWT.MouseExit: shell.dispose(); break; } } }; Listener tableListener = new Listener() { Shell tip = null; Label label = null; public void handleEvent(Event event) { switch (event.type) { case SWT.Dispose: case SWT.KeyDown: case SWT.MouseMove: { if (tip == null) break; tip.dispose(); tip = null; label = null; break; } case SWT.MouseHover: { TableItem item = table.getItem(new Point(event.x, event.y)); if (item != null) { if (tip != null && !tip.isDisposed()) tip.dispose(); tip = new Shell(shell, SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL); tip.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); FillLayout layout = new FillLayout(); layout.marginWidth = 2; tip.setLayout(layout); label = new Label(tip, SWT.NONE); label.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND)); label.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); label.setData("_TABLEITEM", item); label.setText(item.getText()); label.addListener(SWT.MouseExit, labelListener); label.addListener(SWT.MouseDown, labelListener); Point size = tip.computeSize(SWT.DEFAULT, SWT.DEFAULT); Rectangle rect = item.getBounds(0); Point pt = table.toDisplay(rect.x, rect.y); tip.setBounds(pt.x, pt.y, size.x, size.y); tip.setVisible(true); } } } } }; table.addListener(SWT.Dispose, tableListener); table.addListener(SWT.KeyDown, tableListener); table.addListener(SWT.MouseMove, tableListener); table.addListener(SWT.MouseHover, tableListener); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:eu.stratosphere.addons.visualization.swt.SWTGateToolTip.java
public SWTGateToolTip(Shell parent, ManagementGate managementGate, int x, int y) { super(parent, x, y); int height;/* w ww. j a va 2 s . com*/ this.managementGate = managementGate; if (managementGate.isInputGate()) { setTitle("Input Gate " + managementGate.getIndex()); } else { setTitle("Output Gate " + managementGate.getIndex()); } final Color backgroundColor = getShell().getBackground(); final Color foregroundColor = getShell().getForeground(); final GateVisualizationData gateVisualizationData = (GateVisualizationData) managementGate.getAttachment(); if (gateVisualizationData.isProfilingEnabled()) { this.chart = createChart(gateVisualizationData, backgroundColor); this.chart.setLayoutData(new GridData(GridData.FILL_BOTH)); height = 200; } else { this.chart = null; height = 100; } final Composite tableComposite = new Composite(getShell(), SWT.NONE); tableComposite.setBackground(backgroundColor); tableComposite.setForeground(foregroundColor); final GridLayout tableGridLayout = new GridLayout(2, false); tableGridLayout.marginHeight = 0; tableGridLayout.marginLeft = 0; tableComposite.setLayout(tableGridLayout); // Channel type ChannelType channelType; if (managementGate.isInputGate()) { channelType = managementGate.getVertex().getGroupVertex().getBackwardEdge(managementGate.getIndex()) .getChannelType(); } else { channelType = managementGate.getVertex().getGroupVertex().getForwardEdge(managementGate.getIndex()) .getChannelType(); } final Label channelTypeTextLabel = new Label(tableComposite, SWT.NONE); channelTypeTextLabel.setBackground(backgroundColor); channelTypeTextLabel.setForeground(foregroundColor); channelTypeTextLabel.setText("Channel type:"); this.channelTypeLabel = new Label(tableComposite, SWT.NONE); this.channelTypeLabel.setBackground(backgroundColor); this.channelTypeLabel.setForeground(foregroundColor); this.channelTypeLabel.setText(channelType.toString()); if (!this.managementGate.isInputGate()) { final ManagementGroupEdge groupEdge = this.managementGate.getVertex().getGroupVertex() .getForwardEdge(this.managementGate.getIndex()); final GroupEdgeVisualizationData groupEdgeVisualizationData = (GroupEdgeVisualizationData) groupEdge .getAttachment(); if (groupEdgeVisualizationData.isIOBottleneck()) { this.warningComposite = createWarningComposite(WARNINGTEXT, SWT.ICON_WARNING); height += ICONSIZE; } else { this.warningComposite = null; } } else { this.warningComposite = null; } getShell().setSize(WIDTH, height); finishInstantiation(x, y, WIDTH, false); }
From source file:eu.stratosphere.addons.visualization.swt.SWTVertexToolTip.java
public SWTVertexToolTip(Shell parent, final SWTToolTipCommandReceiver commandReceiver, ManagementVertex managementVertex, int x, int y) { super(parent, x, y); this.managementVertex = managementVertex; final VertexVisualizationData vertexVisualizationData = (VertexVisualizationData) managementVertex .getAttachment();/* w w w . ja v a 2 s . c om*/ int height; final Color backgroundColor = getShell().getBackground(); final Color foregroundColor = getShell().getForeground(); // Set the title final String taskName = managementVertex.getName() + " (" + (managementVertex.getIndexInGroup() + 1) + " of " + managementVertex.getNumberOfVerticesInGroup() + ")"; setTitle(taskName); // Only create chart if profiling is enabled if (vertexVisualizationData.isProfilingEnabledForJob()) { this.threadChart = createThreadChart(vertexVisualizationData, backgroundColor); this.threadChart.setLayoutData(new GridData(GridData.FILL_BOTH)); height = 240; // should be 265 when cancel button is enabled } else { this.threadChart = null; height = 125; } final Composite tableComposite = new Composite(getShell(), SWT.NONE); tableComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); tableComposite.setBackground(backgroundColor); tableComposite.setForeground(foregroundColor); final GridLayout tableGridLayout = new GridLayout(3, false); tableGridLayout.marginHeight = 0; tableGridLayout.marginLeft = 0; tableComposite.setLayout(tableGridLayout); final GridData gridData1 = new GridData(); gridData1.horizontalSpan = 2; gridData1.grabExcessHorizontalSpace = true; gridData1.widthHint = 200; final GridData gridData2 = new GridData(); gridData2.grabExcessHorizontalSpace = true; // Instance type final Label instanceTypeTextLabel = new Label(tableComposite, SWT.NONE); instanceTypeTextLabel.setBackground(backgroundColor); instanceTypeTextLabel.setForeground(foregroundColor); instanceTypeTextLabel.setText("Instance type:"); this.instanceTypeLabel = new Label(tableComposite, SWT.NONE); this.instanceTypeLabel.setBackground(backgroundColor); this.instanceTypeLabel.setForeground(foregroundColor); this.instanceTypeLabel.setText(this.managementVertex.getInstanceType()); this.instanceTypeLabel.setLayoutData(gridData1); // Instance ID final Label instanceIDTextLabel = new Label(tableComposite, SWT.NONE); instanceIDTextLabel.setBackground(backgroundColor); instanceIDTextLabel.setForeground(foregroundColor); instanceIDTextLabel.setText("Instance ID:"); this.instanceIDLabel = new Label(tableComposite, SWT.NONE); this.instanceIDLabel.setBackground(backgroundColor); this.instanceIDLabel.setForeground(foregroundColor); this.instanceIDLabel.setText(this.managementVertex.getInstanceName()); this.instanceIDLabel.setLayoutData(gridData2); final Button switchToInstanceButton = new Button(tableComposite, SWT.PUSH); switchToInstanceButton.setText("Switch to instance..."); switchToInstanceButton.setEnabled(vertexVisualizationData.isProfilingEnabledForJob()); switchToInstanceButton.setVisible(false); /* * final String instanceName = this.managementVertex.getInstanceName(); * switchToInstanceButton.addListener(SWT.Selection, new Listener() { * @Override * public void handleEvent(Event arg0) { * commandReceiver.switchToInstance(instanceName); * } * }); */ // Execution state final Label executionStateTextLabel = new Label(tableComposite, SWT.NONE); executionStateTextLabel.setBackground(backgroundColor); executionStateTextLabel.setForeground(foregroundColor); executionStateTextLabel.setText("Execution state:"); this.executionStateLabel = new Label(tableComposite, SWT.NONE); this.executionStateLabel.setBackground(backgroundColor); this.executionStateLabel.setForeground(foregroundColor); this.executionStateLabel.setText(this.managementVertex.getExecutionState().toString()); this.executionStateLabel.setLayoutData(gridData1); final ManagementGroupVertex groupVertex = this.managementVertex.getGroupVertex(); final GroupVertexVisualizationData groupVertexVisualizationData = (GroupVertexVisualizationData) groupVertex .getAttachment(); if (groupVertexVisualizationData.isCPUBottleneck()) { this.warningComposite = createWarningComposite(WARNINGTEXT, SWT.ICON_WARNING); height += ICONSIZE; } else { this.warningComposite = null; } // Available task actions final Composite taskActionComposite = new Composite(getShell(), SWT.NONE); taskActionComposite.setLayout(new RowLayout(SWT.HORIZONTAL)); taskActionComposite.setBackground(backgroundColor); taskActionComposite.setForeground(foregroundColor); /* * final Button cancelTaskButton = new Button(taskActionComposite, SWT.PUSH); * final ManagementVertexID vertexID = this.managementVertex.getID(); * cancelTaskButton.setText("Cancel task"); * cancelTaskButton.setEnabled(this.managementVertex.getExecutionState() == ExecutionState.RUNNING); * cancelTaskButton.addListener(SWT.Selection, new Listener() { * @Override * public void handleEvent(Event arg0) { * commandReceiver.cancelTask(vertexID, taskName); * } * }); */ getShell().setSize(WIDTH, height); finishInstantiation(x, y, WIDTH, false); }
From source file:eu.stratosphere.nephele.visualization.swt.SWTVertexToolTip.java
public SWTVertexToolTip(Shell parent, final SWTToolTipCommandReceiver commandReceiver, ManagementVertex managementVertex, int x, int y) { super(parent, x, y); this.managementVertex = managementVertex; final VertexVisualizationData vertexVisualizationData = (VertexVisualizationData) managementVertex .getAttachment();//w w w . j a va 2s.c o m int height; final Color backgroundColor = getShell().getBackground(); final Color foregroundColor = getShell().getForeground(); // Set the title final String taskName = managementVertex.getName() + " (" + (managementVertex.getIndexInGroup() + 1) + " of " + managementVertex.getNumberOfVerticesInGroup() + ")"; setTitle(taskName); // Only create chart if profiling is enabled if (vertexVisualizationData.isProfilingEnabledForJob()) { this.threadChart = createThreadChart(vertexVisualizationData, backgroundColor); this.threadChart.setLayoutData(new GridData(GridData.FILL_BOTH)); height = 240; // should be 265 when cancel button is enabled } else { this.threadChart = null; height = 125; } final Composite tableComposite = new Composite(getShell(), SWT.NONE); tableComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); tableComposite.setBackground(backgroundColor); tableComposite.setForeground(foregroundColor); final GridLayout tableGridLayout = new GridLayout(3, false); tableGridLayout.marginHeight = 0; tableGridLayout.marginLeft = 0; tableComposite.setLayout(tableGridLayout); final GridData gridData1 = new GridData(); gridData1.horizontalSpan = 2; gridData1.grabExcessHorizontalSpace = true; gridData1.widthHint = 200; final GridData gridData2 = new GridData(); gridData2.grabExcessHorizontalSpace = true; // Instance type final Label instanceTypeTextLabel = new Label(tableComposite, SWT.NONE); instanceTypeTextLabel.setBackground(backgroundColor); instanceTypeTextLabel.setForeground(foregroundColor); instanceTypeTextLabel.setText("Instance type:"); this.instanceTypeLabel = new Label(tableComposite, SWT.NONE); this.instanceTypeLabel.setBackground(backgroundColor); this.instanceTypeLabel.setForeground(foregroundColor); this.instanceTypeLabel.setText(this.managementVertex.getInstanceType()); this.instanceTypeLabel.setLayoutData(gridData1); // Instance ID final Label instanceIDTextLabel = new Label(tableComposite, SWT.NONE); instanceIDTextLabel.setBackground(backgroundColor); instanceIDTextLabel.setForeground(foregroundColor); instanceIDTextLabel.setText("Instance ID:"); this.instanceIDLabel = new Label(tableComposite, SWT.NONE); this.instanceIDLabel.setBackground(backgroundColor); this.instanceIDLabel.setForeground(foregroundColor); this.instanceIDLabel.setText(this.managementVertex.getInstanceName()); this.instanceIDLabel.setLayoutData(gridData2); final Button switchToInstanceButton = new Button(tableComposite, SWT.PUSH); switchToInstanceButton.setText("Switch to instance..."); switchToInstanceButton.setEnabled(vertexVisualizationData.isProfilingEnabledForJob()); switchToInstanceButton.setVisible(false); /* * final String instanceName = this.managementVertex.getInstanceName(); * switchToInstanceButton.addListener(SWT.Selection, new Listener() { * @Override * public void handleEvent(Event arg0) { * commandReceiver.switchToInstance(instanceName); * } * }); */ // Execution state final Label executionStateTextLabel = new Label(tableComposite, SWT.NONE); executionStateTextLabel.setBackground(backgroundColor); executionStateTextLabel.setForeground(foregroundColor); executionStateTextLabel.setText("Execution state:"); this.executionStateLabel = new Label(tableComposite, SWT.NONE); this.executionStateLabel.setBackground(backgroundColor); this.executionStateLabel.setForeground(foregroundColor); this.executionStateLabel.setText(this.managementVertex.getExecutionState().toString()); this.executionStateLabel.setLayoutData(gridData1); // Checkpoint state final Label checkpointStateTextLabel = new Label(tableComposite, SWT.NONE); checkpointStateTextLabel.setBackground(backgroundColor); checkpointStateTextLabel.setForeground(foregroundColor); checkpointStateTextLabel.setText("Checkpoint state:"); this.checkpointStateLabel = new Label(tableComposite, SWT.NONE); this.checkpointStateLabel.setBackground(backgroundColor); this.checkpointStateLabel.setForeground(foregroundColor); this.checkpointStateLabel.setText(this.managementVertex.getCheckpointState().toString()); this.checkpointStateLabel.setLayoutData(gridData1); final ManagementGroupVertex groupVertex = this.managementVertex.getGroupVertex(); final GroupVertexVisualizationData groupVertexVisualizationData = (GroupVertexVisualizationData) groupVertex .getAttachment(); if (groupVertexVisualizationData.isCPUBottleneck()) { this.warningComposite = createWarningComposite(WARNINGTEXT, SWT.ICON_WARNING); height += ICONSIZE; } else { this.warningComposite = null; } // Available task actions final Composite taskActionComposite = new Composite(getShell(), SWT.NONE); taskActionComposite.setLayout(new RowLayout(SWT.HORIZONTAL)); taskActionComposite.setBackground(backgroundColor); taskActionComposite.setForeground(foregroundColor); /* * final Button cancelTaskButton = new Button(taskActionComposite, SWT.PUSH); * final ManagementVertexID vertexID = this.managementVertex.getID(); * cancelTaskButton.setText("Cancel task"); * cancelTaskButton.setEnabled(this.managementVertex.getExecutionState() == ExecutionState.RUNNING); * cancelTaskButton.addListener(SWT.Selection, new Listener() { * @Override * public void handleEvent(Event arg0) { * commandReceiver.cancelTask(vertexID, taskName); * } * }); */ getShell().setSize(WIDTH, height); finishInstantiation(x, y, WIDTH, false); }
From source file:ChooseFont.java
/** * Creates the window contents/* w ww .j a v a2s . c o m*/ * * @param shell the parent shell */ private void createContents(final Shell shell) { shell.setLayout(new GridLayout(2, false)); final Label fontLabel = new Label(shell, SWT.NONE); fontLabel.setText("The selected font"); Button button = new Button(shell, SWT.PUSH); button.setText("Font..."); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { // Create the color-change dialog FontDialog dlg = new FontDialog(shell); // Pre-fill the dialog with any previous selection if (font != null) dlg.setFontList(fontLabel.getFont().getFontData()); if (color != null) dlg.setRGB(color.getRGB()); if (dlg.open() != null) { // Dispose of any fonts or colors we have created if (font != null) font.dispose(); if (color != null) color.dispose(); // Create the new font and set it into the label font = new Font(shell.getDisplay(), dlg.getFontList()); fontLabel.setFont(font); // Create the new color and set it color = new Color(shell.getDisplay(), dlg.getRGB()); fontLabel.setForeground(color); // Call pack() to resize the window to fit the new font shell.pack(); } } }); }