I have an SWT window wherein there is Group widget in which i placed couple of other widgets,i set the title of group & its working fine. The group title color is blue always(in my case i am not sure) and that doesn't sync up with other children inside group.So i wonder if there is a way to change the group title text color and font if there is a way ?
It's quite easy to change font of group, check this snippet (used snippet from java2s.com)
//Send questions, comments, bug reports, etc. to the authors:
//Rob Warner (rwarner#interspatial.com)
//Robert Harris (rbrt_harris#yahoo.com)
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
/**
* This class demonstrates groups
*/
public class GroupExample {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new GridLayout());
// Create the first group
Group group1 = new Group(shell, SWT.SHADOW_IN);
group1.setText("Who's your favorite?");
group1.setLayout(new RowLayout(SWT.VERTICAL));
group1.setFont(new Font(display, "Consolas", 10, SWT.BOLD));
new Button(group1, SWT.RADIO).setText("John");
new Button(group1, SWT.RADIO).setText("Paul");
new Button(group1, SWT.RADIO).setText("George");
new Button(group1, SWT.RADIO).setText("Ringo");
// Create the second group
Group group2 = new Group(shell, SWT.NO_RADIO_GROUP);
group2.setText("Who's your favorite?");
group2.setLayout(new RowLayout(SWT.VERTICAL));
group2.setForeground(new Color(display, new RGB(255, 0, 0)));
new Button(group2, SWT.RADIO).setText("Barry");
new Button(group2, SWT.RADIO).setText("Robin");
new Button(group2, SWT.RADIO).setText("Maurice");
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
}
It provides this behavior on W7
But as you can see, change of color by setForeground(Color c) doesn't change a thing, when I search for additional info I found bug report on SWT bugzilla The color of the title of the group control cannot be changed. It's windows platform dependent bug.
But you can try a Group without text + a Label widget, this maybe a solution if you just want a better GUI.
Related
I need to draw an ImageHyperlink that looks exactly like the ones in
Eclipse's welcome page where the text consists of bold title and
description but I can't find this feature in the ImageHyperlink widget
itself, do I have to override the paintHyperlink() myself ? if so, could
someone provide a snippet?
If I read the source correctly (and it is very complex) the welcome page is actually done using HTML and not ImageHyperlink.
You an override the paintHyperlink method of ImageHyperlink:
protected void paintHyperlink(GC gc, Rectangle bounds)
so you should be able to do something similar.
Or, as an option, you can try to mimic appearance, by using standard approach of creating composites (just style it as you wish;)):
private void demoHyperlinks() {
form.getBody().setLayout(new GridLayout());
Composite container = new Composite(form.getBody(), SWT.NONE);
container.setLayout(new GridLayout());
ImageHyperlink imageHyperlink = toolkit.createImageHyperlink(container, SWT.NULL);
imageHyperlink.setText("This is an image hyperlink.");
imageHyperlink.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_BLUE));
imageHyperlink.setFont(new Font(form.getDisplay(), new FontData("Verdana", 20, SWT.BOLD)));
imageHyperlink.setImage(new Image(getShell().getDisplay(), "images/help.gif"));
imageHyperlink.addHyperlinkListener(new HyperlinkAdapter() {
#Override
public void linkActivated(HyperlinkEvent e) {
System.out.println("Image hyperlink activated.");
}
});
Composite descriptionContainer = new Composite(container, SWT.NONE);
GridLayout gl = new GridLayout();
gl.marginLeft = 25;
descriptionContainer.setLayout(gl);
Hyperlink hyperlink = toolkit.createHyperlink(descriptionContainer, "This is a hyperlink link", SWT.NULL);
hyperlink.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_BLUE));
HyperlinkGroup group = new HyperlinkGroup(getShell().getDisplay());
group.add(imageHyperlink);
group.add(hyperlink);
group.setHyperlinkUnderlineMode(HyperlinkSettings.UNDERLINE_NEVER);
}
I am trying a sample with icePDF . Everything is working fine but i need to disable the toolbar which appears at the top. i tried few things but its not working. Can some body please help me out with it. Below is my code.
//package XML.test;
package applet;
import java.util.ResourceBundle;
import javax.swing.JFrame;
import javax.swing.JPanel;
import org.icepdf.ri.common.ComponentKeyBinding;
import org.icepdf.ri.common.SwingController;
import org.icepdf.ri.common.SwingViewBuilder;
import org.icepdf.ri.util.PropertiesManager;
import org.icepdf.core.pobjects.fonts.*;
import org.icepdf.core.views.DocumentViewController;
import org.icepdf.core.*;
public class ViewerComponentExample
{
static void buildFrame(String filepath)
{
System.getProperties().put("org.icepdf.core.scaleImages", "false");
System.getProperties().put("org.icepdf.core.imageReference","smoothScaled");
System.getProperties().put("org.icepdf.core.target.dither", "VALUE_DITHER_DISABLE");
System.getProperties().put("org.icepdf.core.target.fractionalmetrics", "VALUE_FRACTIONALMETRICS_OFF");
System.getProperties().put("org.icepdf.core.target.interpolation", "VALUE_INTERPOLATION_NEAREST_ NEIGHBOR");
System.getProperties().put("org.icepdf.core.screen.interpolation", "VALUE_INTERPOLATION_NEAREST_NEIGHBOR");
System.getProperties().put("org.icepdf.core.awtFontLoading","true");
SwingController controller = new SwingController();
PropertiesManager properties = new PropertiesManager(System.getProperties(), ResourceBundle.getBundle(PropertiesManager.DEFAULT_MESSAGE_BUNDLE));
properties.setBoolean(PropertiesManager.PROPERTY_SHOW_TOOLBAR_ANNOTATION, Boolean.FALSE);
properties.setBoolean(PropertiesManager.PROPERTY_SHOW_TOOLBAR_FIT, Boolean.FALSE);
// Build a SwingViewFactory configured with the controller
SwingViewBuilder factory = new SwingViewBuilder(controller);
JPanel viewerComponentPanel = factory.buildViewerPanel();
// add copy keyboard command
ComponentKeyBinding.install(controller, viewerComponentPanel);
// add interactive mouse link annotation support via callback
controller.getDocumentViewController().setAnnotationCallback(
new org.icepdf.ri.common.MyAnnotationCallback(
controller.getDocumentViewController()));
// Use the factory to build a JPanel that is pre-configured
//with a complete, active Viewer UI.
// Create a JFrame to display the panel in
JFrame window = new JFrame("Metrics Wizard Help");
window.getContentPane().add(viewerComponentPanel);
window.pack();
window.setVisible(true);
controller.setPageFitMode(DocumentViewController.PAGE_FIT_WINDOW_WIDTH, false);
controller.openDocument(filepath);
}
public static void main(String args[])
{
String filepath = "C:/Users/vishalt/Workspaces/Eclipse 4.2 Java/htmltopdf/src/XML/output/SCB_TEST.pdf";
buildFrame(filepath);
}
}
private SwingController controller;
controller = new SwingController();
SwingViewBuilder viewBuilder = new SwingViewBuilder(controller, properties);
JPanel panel = viewBuilder.buildViewerPanel();
controller.setToolBarVisible(false);
You have to set the toolbar invisible because icePdf looks in the PDF-document for the property and overwrites your setting with default when there is no document opened!
There are two ways to this.
1) Follow this example to set all the toolbars to false.
http://www.icesoft.org/JForum/posts/list/17673.page#sthash.48ICrL2A.dpbs
2) You can modify or remove the toolbar by editing the source code for SwingViewBuilder.
Here is a link to the code: http://sventon.icesoft.org/svn/repos/repo/show//icepdf/trunk/icepdf/viewer/src/org/icepdf/ri/common/SwingViewBuilder.java?revision=34004
You probably want to comment out lines 481 - 483.
481 JToolBar toolBar = buildCompleteToolBar(embeddableComponent);
482 if (toolBar != null)
483 cp.add(toolBar, BorderLayout.NORTH)
Remove your import for SwingViewBuilder and create your own class with those lines commented out.
I want to disable the button maximize/minimize, below I post image to explain
this is my code :
public class ProjectWizardPageOne extends WizardPage {
private String platform;
public ProjectWizardPageOne(String title) {
super(title);
this.setTitle(title);
this.setMessage("Configure Project Name and Location");
}
#Override
public void createControl(Composite parent) {
Composite container = new Composite(parent,SWT.NONE);
setPageComplete(false);
setControl(container);
Canvas leftPanel = new Canvas(container, SWT.NONE);
leftPanel.setBackgroundImage(new Image(leftPanel.getDisplay(), this
.getClass().getClassLoader()
.getResourceAsStream("/icons/mypicture.png")));
leftPanel.setBounds(0, 0, 183, 282);
Composite rightContainer = new Composite(container, SWT.NONE);
rightContainer.setBackground(new Color(null, 255, 255, 255));
rightContainer.setBounds(181, 0, 399, 282);
}
public String getPlatform() {
return platform;
}
public void setPlatform(String platform) {
this.platform = platform;
}
}
I tried to get the Composite's Shell like this "container.getShell();"
but I don't understand How I can set these parameters "SWT.SHELL_TRIM | SWT.TOOL"!
Thanks
Controlling the Window/Shell is not the responsibility of a WizardPage, it can not do that. It's the responsibility of the WizardDialog or the code that creates it. In fact, there is no guarantee that a Wizard and its WizardPages will even be contained in a WizardDialog; anything can implement the IWizardContainer interface to present wizards in a different way.
Is it a File -> New wizard or a custom wizard that is programatically launched. If it is custom, you would have to create WizardDialog and then pass Wizard instance to it. When creating WizardDialog, you would also create Shell, for which you can send the argument without SWT.RESIZE. For File -> New, since the dialog is not created by you, I dont think you can control resize option there. The resize can only be passed in the constructor of Shell.
In case of dialogs, I have observed that I need to explicitly specify that I need min, max buttons at upper-right corner. For that I need to call the below method in a constructor:
setShellStyle(getShellStyle() | SWT.MAX | SWT.MIN | SWT.RESIZE);
Since Wizard is also a dialog, I can call the above method to reset the shellStyle not to include max, min, and other buttons (see above code). The wizard by default might be adding these buttons. But I think you can override this by recalling at the end of wizard creation. Hope this helps.
public class InstallerWizard extends Wizard{
...
main()
{
WizardDialog dialog = new DisableMax(shell, new InstallerWizard());
dialog.open();
}
}
public class DisableMax extends WizardDialog {
public DisableMax(Shell parentShell, IWizard newWizard) {
super(parentShell, newWizard);
setShellStyle(SWT.CLOSE | SWT.MIN | SWT.RESIZE | getDefaultOrientation());
}
}
I am facing an issue with the SWT Combo in my eclipse RCP application.
I will try explaining my issue with a use case for better understanding.
I have a combo box in a Eclipse RCP View with values say "A", "B","C","D" and i have a submit button beside it & a SWT table right below it.
Once the value is changed in the Combo and submit button is clicked, records would be displayed in the table.
Let us suppose "A" is selected by default and records of A are displayed in the table on view invocation.
Now I select "B" from the drop down and click submit. I see only the records of "A" in the table although the combo shows "B".
ONLY if I select "B" again from the combo and then click submit, "B"'s records gets displayed.
Now if I select C from the combo , only "B"'s records gets displayed.
Later, If i select D from the Combo , "C"'s records are displayed.
It seems that only the previous selections is processed and displayed rather than the current selection.
I am not facing this issue in Windows XP or prev versions of windows. I recently shifted to Windows 7 64-bit OS where I faced this issue.
Is this a known issue? Any help would be appreciated.
You use a drop down listener for storing the selected index. The drop down listener is triggered when the combo list drops down. At this time, the old selection is stored. If you select a new item in the list, the listener will not be triggered again. Though you always get the previous selected item index if you press the submit button later on.
To get what you want, you must use a selection listener instead of the drop down listener and all works fine. The selection listener is called when you select an item in the drop down list. Just replace SWT.DropDown with SWT.Selection.
filter.addListener(SWT.Selection, new Listener() {...});
Please find the sample code below
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
public class TestCombo {
private static String[] filterByText = new String[] {"A","B","C","D"};
static int index = 0;
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
Composite comp = new Composite(shell, SWT.NONE);
GridLayout layout = new GridLayout(2, false);
GridData gridData = new GridData(SWT.FILL,SWT.FILL,true,false);
comp.setLayout(layout);
comp.setLayoutData(gridData);
final Combo filter = new Combo (comp, SWT.READ_ONLY);
filter.setItems (filterByText );
filter.setText (filterByText[0]);
filter.setVisibleItemCount( filterByText.length );
filter.addListener(SWT.DROP_DOWN, new Listener() {
#Override
public void handleEvent(Event event) {
index = filter.getSelectionIndex();
}
});
Button submit = new Button (comp, SWT.PUSH);
submit.setText ("Submit");
GridData data = new GridData();
data.widthHint = 80;
submit.setLayoutData(data);
submit.addSelectionListener (new SelectionAdapter () {
public void widgetSelected(SelectionEvent e) {
System.out.println("The index is ==> "+index);
}
});
comp.pack();
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
How to edit SWT table Values without Using Mouse Listeners?
Do the TableEditor snippets in the below link help?
SWT Snippets
The first example in the TableEditor section uses a SelectionListener on the table (unlike the second example which uses a MouseDown event you mentioned you don't want)
You could perhaps make use of the TraverseListener or KeyListener too to help you achieve what you want.
final int EDITABLECOLUMN = 1;
tblProvisionInfo.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(SelectionEvent e) {
// Clean up any previous editor control
final TableEditor editor = new TableEditor(tblProvisionInfo);
// The editor must have the same size as the cell and must
// not be any smaller than 50 pixels.
editor.horizontalAlignment = SWT.LEFT;
editor.grabHorizontal = true;
editor.minimumWidth = 50;
Control oldEditor = editor.getEditor();
if (oldEditor != null)
oldEditor.dispose();
// Identify the selected row
TableItem item = (TableItem) e.item;
if (item == null)
return;
// The control that will be the editor must be a child of the
// Table
Text newEditor = new Text(tblProvisionInfo, SWT.NONE);
newEditor.setText(item.getText(EDITABLECOLUMN));
newEditor.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent me) {
Text text = (Text) editor.getEditor();
editor.getItem()
.setText(EDITABLECOLUMN, text.getText());
}
});
newEditor.selectAll();
newEditor.setFocus();
editor.setEditor(newEditor, item, EDITABLECOLUMN);
}
});
Here tblProvision is the name of your table. you can just now edit Your table by clicking on it. I have Declare EDITABLECOLUMN. this is the column that u want to edit.
If you can use JFace as well and not just pain SWT, have a look at the JFace Snippets, especially
Snippet036FocusBorderCellHighlighter - Demonstrates keyboard navigation by highlighting the currently selected cell with a focus border showing once more the flexibility of the new cell navigation support
Snippet034CellEditorPerRowNewAPI - Demonstrates different CellEditor-Types in one COLUMN with 3.3-API of JFace-Viewers
You can get or set the value of a item, for example:
Table table = new Table(parent, SWT.NONE);
TableItem item = new TableItem(table, SWT.NONE);
item.setText("My new Text");
I suggest you to us TableViewer, it is very powerful table which it you can use databinding very easy too.