I'm looking for tips/tutorials for displaying an image in a SWT/JFace dialog box.
Can someone please point me to the right way?
Take a look at the official tutorial.
If it is clickable:
Image image = new Image(display,
ShellWithButtonShowingEclipseLogo.class.getResourceAsStream(
"yourpicture"));
Button button = new Button(shell,SWT.PUSH);
button.setImage(image);
If it is not clickable then you can use Label instead of Button.
From your question i understood that you are trying to display
an image in the title area of the daialog Box.
You can make use of the "setTitleImage(Image image)" function in
your main class (class which extends the Dialog )
example:
class DemoDialog extends TitleAreaDialog {
public DemoDialog(Shell parentShell) {
super(parentShell);
}
protected Control createDialogArea(Composite parent) {
setTitle("Demo dialog...");
setTitleImage(ImageObject) // Image to be displayed in your Dialog
}
}
Related
I have got a code snippet to display image in SWT Application which is
Image image = new Image(display, "c:\\temp\\swt.png");
To display the same in View of RCP application?
What do i do? How do i display the image from an Absolute Path?
View{
createPartControl(){
Image image = new Image(display, "c:\\temp\\swt.png");
}
}
We cant use "display" in the createPartControl method.
The display is also available in a view. There are several ways to get it, one of which is:
Display display = Display.getDefault();
new Image(display, ....);
Your view is also given a Composite so you can also do:
public void createPartControl(Composite parent)
{
.... other code ...
Display display = parent.getDisplay();
new Image(display, ....);
The one thing you must not do is try to create a new Display object.
I created a dialog and added a button actor.
windowStyle = new Window.WindowStyle(boldFont, Color.WHITE, drawable);
dialog = new Dialog("Error", windowStyle);
dialog.getContentTable().add(resetButton);
but the problem is that when I do dialog.show(stage) only the background of the dialog is at the center, and the string "Error" is at the top left corner of the dialog background while the resetButton is also not aligned.
You can do several things here. The Dialog class has at last three tables in it. The "Error" string is added to the titleTable. You could create an empty titled Dialog:
dialog = new Dialog("", windowStyle);
and then add and center your title manually:
dialog.getTitleTable().add(new Label("Error", new Label.LabelStyle(boldFont, Color.WHITE)).center().expand();
Same for the resetButton, but you could use the getContentTable() or getButtonTable() methods.
If you want to resize or reposition your dialog window, I found the only way to do so is to create your own Dialog class, MyDialog extends Dialog and override the getPrefHeight(), getPrefWidth() and setPosition(x, y) methods.
I am currently working on a school project where we are creating a GWT web application which uses a GeoChart widget to display information about the servers we have crawled. Simply put, I would wish to create a text box on top of our GeoChart widget which shows an interactive world map that takes up the whole screen right now to input information. I have searched quite extensively but I have been unable to come up with an answer.
Here is the code as follows:
#Override
public void onModuleLoad() {
dataReader = (DataReaderAsync) GWT.create(DataReader.class);
RootLayoutPanel.get().add(getSimpleLayoutPanel());
// Create the API Loader
ChartLoader chartLoader = new ChartLoader(ChartPackage.CORECHART);
chartLoader.loadApi(new Runnable() {
#Override
public void run() {
getSimpleLayoutPanel().setWidget(getGeoChart());
drawGeoChart();
}
});
}
As GeoChart is a widget, it is wrapped under(i am not sure if this is the right word) a SimpleLayoutPanel right now which will display it into a full screen. As stated above, I would wish to include text above the geoChart. From my understanding, I would need to create another widget containing my text and add both the GeoChart widget and the text box widget into it. What would be the best way to go about doing this?
I believe DialogBox could solve your problem. People usually program the DialogBox in a way that it only pops up into display when certain event is triggered and disappears after user finishes some operation. In your particular case, you can simply make the DialogBox shows up from the beginning and never disappears. And the best part of it: you don't need to add the DialogBox widget to the geoChart widget. Calling dialogBox.center() or dialogBox.show() will do the magic for you.
Here is the sample code.
#Override
public void onModuleLoad() {
dataReader = (DataReaderAsync) GWT.create(DataReader.class);
RootLayoutPanel.get().add(getSimpleLayoutPanel());
// Create the API Loader
ChartLoader chartLoader = new ChartLoader(ChartPackage.CORECHART);
chartLoader.loadApi(new Runnable() {
#Override
public void run() {
getSimpleLayoutPanel().setWidget(getGeoChart());
drawGeoChart();
}
});
// NOTE: the first argument 'false' makes sure that this dialog box
// will not disappear when user clicks outside of it
// NOTE: the second argument 'false' makes sure that mouse and keyboard
// events outside of the dialog box will NOT be ignored
DialogBox dialogBox = new DialogBox(false, false);
DialogBox.setText("Demo");
HorizontalPanel panel = new HorizontalPanel();
panel.setSpacing(5);
InlineLabel labelOfTextBox = new InlineLabel("Label");
TextBox textBox = new TextBox();
panel.add(labelOfTextBox);
panel.add(textBox);
dialogBox.setWidget(panel);
// show up in the center
dialogBox.center();
}
Dear all thanks for answering my question. To rectify this problem, I have made use of the custom widget API within GWT(known as Composite). Here's the code as below:
private static class CombinedWidget extends Composite {
public CombinedWidget() {
// place the check above the text box using a vertical panel.
VerticalPanel panel = new VerticalPanel();
DockLayoutPanel dPanel = new DockLayoutPanel(Unit.EM);
panel.setSpacing(13);
panel.add(nameProject);
nameProject.setStyleName("gwt-Group-Label");
panel.add(className);
panel.add(nameKs);
panel.add(nameEsmond);
panel.add(nameBowen);
panel.add(nameAaron);
dPanel.addWest(panel, 13);
dPanel.add(getGeoChart());
// all composites must call initWidget() in their constructors.
initWidget(dPanel);
setWidth("100%");
}
Actually I sort of changed from the original idea. Instead of putting it on the very top, I attached the labels into a VerticalPanel and then created a CombinedWidget(custom widget) which adds both a VerticalPanel and DockLayoutPanel together. I then added the VerticalPanel(containing all the labels) and the GeoChart into the DockLayoutPanel.
This solved my problem of displaying both the labels and the GeoChart on the same page(as originally i added it into a VerticalPanel but it would not work as the app would not read the GeoChart due to the VerticalPanel being overlayed on top of the GeoChart).
If you guys want a picture of my app to visualise, please say so!
How can i add a button without text only with marker for forward and backward action for example for widget ListBox in gwt? i tried something like this:
Button btn = new Button("Forward");
btn.setHTML(("<img border='0' src='image\\B_forwards.png' />"));
but can't get the picture to show on button.
You don't need a button. Add an Image widget, and add a ClickHandler to it.
If you just want to add an image to a normal GWT Button, then PushButton is the way to go:
PushButton pushButton = new PushButton(new Image("test.png"));
Otherwise, if you just want to have a clickable image, you still can do that:
public interface MyResources extends ClientBundle{
MyResources INSTANCE = GWT.create(AppImages.class);
#Source("image.gif")
ImageResource image();
}
Image image = new Image( MyResources.INSTANCE.image() );
image.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
// do whatever you want
}
} );
I have a class "View" which extends a ViewPart.
After sth in my class I want to show a dialog, which contains of two labels.
First I used "InputDialog" like this:
Composite composite = new Composite(top, SWT.NONE);
Label label= new Label(tmpComposite, SWT.NONE);
label.setText("");
InputDialog dlg;
dlg = new InputDialog(Display.getCurrent().getActiveShell(),
"Title", "Some Text", label.getText(), insertValidator());
if (dlg.open() == Window.OK) {
//Do sth.
}
This works. But now I have two labels. How can I realize it?
I found a few solutions, but none of them is working in a ViewPart or with Eclipse RCP.
Thanks for your help!
By the way if your solution is to call a java class from my "View", how can I come back to "View" and how can I see my new dialog? Tried it, not working.
You need to create a custom dialog by extending org.eclipse.jface.dialogs.Dialog:
public class MyDialog extends Dialog
{
public MyDialog(Shell parentShell)
{
super(parentShell);
}
#Override
protected Control createDialogArea(Composite parent)
{
Composite container = (Composite)super.createDialogArea(parent);
// Add your controls here
return container;
}
}
You use this in a similar way to InputDialog
MyDialog dialog = new MyDialog(shell);
dialog.open();
Have a look at http://www.vogella.com/articles/EclipseDialogs/article.html for some more details.