so I have
A Part with : (I will spare you the layout details, it's just to show my setup)
sc = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
drawingPane = new Composite(sc, SWT.NONE);
drawingPane.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_BLACK));
sc.setContent(drawingPane);
paintCanvas = new Canvas(drawingPane, SWT.NO_REDRAW_RESIZE | SWT.NO_BACKGROUND);
When I add then a MouseWheelListener to the Canvas, each Time the event occurs, the vertical Scrollbar of the ScrolledComposite is also reacting to it.
Which is kind of annoying. I tried the Solution of this Question. But the Thing is that the Canvas is the Source of the Event, which is right and I need it to be.
The question is more how can I prohibit the MouseEvent to get passed on to the ScrolledComposite?
I also tried to disable the Scrollbar, but this wasn't practical as I have found no place in the Code to re-enable it afterwards. As it seems that the scrolling gets triggered after anything else(like the redraw of my canvas for example).
A bit more Code would be helpful. Anyway, you could try the following:
paintCanvas.addListener(SWT.MouseVerticalWheel, new Listener() {
#Override
public void handleEvent(Event event) {
event.doit = false;
}
});
But I don't think that this will work, since MouseEvents aren't TraverseEvents. I couldn't test it for myself with your code snippet.
Related
I am newbie with swt and I have a Dialog that contains an image but if the image is too big is not possible to see the complete image. It is cut. So I decided to create a Dialog with scrolling. I have done but the scroll doesn't work. It appears and you can clic over and move it but I can't move over the image. I have tried several things but none of them work :(
protected Control createDialogArea(Composite parent) {
//getShell().setText(Messages.labelTitle);
//setTitleImage(image); // Image to be displayed in your Dialog
//return parent;
Composite container = new Composite(getShell(), SWT.H_SCROLL | SWT.V_SCROLL);
container.setLayoutData(new GridData(GridData.FILL_BOTH));
container.setLayout(new GridLayout());
Label preview = new Label(container, SWT.NONE);
GridData layoutData = new GridData(GridData.FILL_BOTH);
preview.setLayoutData(layoutData);
preview.setImage(image);
return parent;
}
I'm trying to add JFree step charts to a scrollable view in eclipse as a plugin, but the charts keep resizing (kinda randomly) each time I modify the view's dimensions.
I want to set them to a fixed size, however large or small the view might get (that's why I made it scrollable in the first place) so I tried something like this:
public void createPartControl(final Composite parent) {
ScrolledComposite scrolled = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL);
Composite comp = new Composite(scrolled, SWT.NONE);
comp.setLayout(new FillLayout(SWT.VERTICAL));
final JFreeChart chart = createChart();
ChartComposite chartComposite1 = new ChartComposite(comp, SWT.NONE, chart, true);
// set chart size attempt
chartComposite1.setSize(500, 200);
chartComposite1.redraw();
comp.redraw();
scrolled.redraw();
// ScrolledComposite stuff
scrolled.setContent(comp);
scrolled.setExpandVertical(true);
scrolled.setExpandHorizontal(true);
scrolled.setAlwaysShowScrollBars(true);
scrolled.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent e) {
org.eclipse.swt.graphics.Rectangle r = scrolled.getClientArea();
scrolled.setMinSize(parent.computeSize(r.width, SWT.DEFAULT));
}
});
But it doesn't do anything. The chart keeps auto resizing as I modify the view's size.
Any help?
Make sure that you undestand how layouts work in SWT. Understanding Layouts in SWT is a good start.
chartComposite1.setSize() is useless, it will be overwritten by the layout that was set in comp.setLayout( ... ).
... and forcing controls to redraw() doesn't help either as it doesn't update the location or size of controls.
As I suggested earlier, if you know the size of the charts, use a single columned GridLayout and control the size of the charts through GridData::widthHint and heightHint.
I need your help... I attached an image, I want that the right grid appears at the bottom, below of Estadisticas1, Estadisticas2, Estadisticas3, Estadisticas4
I tried a lot of ways, with GridData, FormLayout and no way!
Also, I tried with setSize and setBounds and in no cases the size or position change, I donĀ“t know why!
There are many ways to do this depending on exactly what you want which you haven't really specified. For example:
public void createPartControl(final Composite parent)
{
Composite body = new Composite(parent, SWT.NONE);
body.setLayout(new FillLayout(SWT.VERTICAL));
Composite topArea = new Composite(body, SWT.BORDER);
// TODO add your 'EstadisticasX' controls to 'topArea'
Composite bottomArea = new Composite(body, SWT.BORDER);
// TODO add bottom grid to 'bottomArea'
}
I am supposed to create a scroll bar in my Eclipse RCP view and I referred to the ScrolledComposite javadoc and taking help from this.
private void createComposite2(final Composite parent,final String text, int compositeNumber)
{
final ScrolledComposite rightScrolled = new ScrolledComposite(parent, SWT.V_SCROLL|SWT.H_SCROLL|SWT.BORDER);
group=GUIToolkit.newGroup(rightScrolled, SWT.NONE, text, null);
rightScrolled.setContent(group);
group.setLayout(new FillLayout());
rightScrolled.setExpandHorizontal(true);
rightScrolled.setExpandVertical(true);
group.setSize(group.computeSize(SWT.DEFAULT, SWT.DEFAULT));
group.setBackground(white);
createPartControl(group,compositeNumber);
}
But instead the scroll is absent. Can anybody tell me what exactly is the problem? In one of the online resources I saw addControlListner. Will that help? If yes, how can I use it?
After some research and hit and trial, i came up with this code,
private void createComposite2(final Composite parent,final String text, int compositeNumber)
{
final ScrolledComposite rightScrolled = new ScrolledComposite(parent, SWT.V_SCROLL|SWT.H_SCROLL);
group=GUIToolkit.newGroup(rightScrolled, SWT.NONE, text, null);
rightScrolled.setContent(group);
rightScrolled.setExpandHorizontal(true);
rightScrolled.setExpandVertical(true);
rightScrolled.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent e) {
org.eclipse.swt.graphics.Rectangle r = rightScrolled.getClientArea();
rightScrolled.setMinSize(group.computeSize(r.width, SWT.DEFAULT));
}
});
group.setLayout(new FillLayout());
group.setBackground(white);
createPartControl(group,compositeNumber);
}
which resulted in scroll coming but it would not readjust to show the window.
Have a look at the first composite with name SOAD. It's the normal size.
and now this is when i push it on left side, the scroll should have been activated, and it is not... It is cropping the content.
How do i fix this
I'm having a few troubles with the dialogs in the eclipse rcp. I wish to have a dialog which shows me a MasterDetailBlock to manage an arbitrary amount of entities shown in a table on the master part with their corresponding DetailPages shown in the detail part. As of now, this is done using a View, but a non-modal dialog seems more fitting for this.
At first, I tried the naive way of just taking the code from the view und put it into the dialog, with a few modifications due to the difference between view and dialog creation. However, most controls were missing. A search on Google, the eclipse forums and here on Stackoverflow did not bring a solution for this. After checking these sites for the solution, I tried to understand what's happening by stepping through the code with the debugger, but that didn't help me either.
The following Code should show a dialog containing section in which a button should be displayed. However, it doesn't:
protected Control createDialogArea(Composite parent) {
parent.setLayout(new GridLayout(1, true));
Section section = toolkit.createSection(parent, ExpandableComposite.EXPANDED | ExpandableComposite.TITLE_BAR);
section.setLayout(new GridLayout());
section.setText("Section");
section.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
Button test = toolkit.createButton(section, "test", SWT.PUSH);
test.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
test.setVisible(true);
section.computeSize(SWT.DEFAULT, SWT.DEFAULT);
return parent;
}
The result of this is:
However, as a MasterDetailBlock needs a form, I'll provide this Code as well:
protected Control createDialogArea(Composite parent) {
parent.setLayout(new GridLayout(1, true));
form = new ScrolledForm(parent);
form.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
form.getBody().setLayout(new FillLayout());
Composite formComposite = toolkit.createComposite(form.getBody());
formComposite.setLayout(new GridLayout(1,true));
Section section = toolkit.createSection(formComposite, ExpandableComposite.EXPANDED | ExpandableComposite.TITLE_BAR);
section.setLayout(new GridLayout());
section.setText("Section");
section.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
Button test = toolkit.createButton(section, "test", SWT.PUSH);
test.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
test.setVisible(true);
section.computeSize(SWT.DEFAULT, SWT.DEFAULT);
return parent;
}
Just a slight modification by adding a form to the dialog and everything goes on the form. However, the result looks like this:
I'm afraid I'm missing something obvious here. As I said, searching didn't bring any enlightment and stepping through the code didn't help either. My last resort "trying stuff to see what happens and try to understand that" didn't help much, as the results didn't change from the ones already posted.
So, do I miss something? (Which I think it is)
If you can provide me a link to show me what's wrong (or anything from your experience as well), I would appriciate that.
Thank you for your help.
There is a
section.setClient(test);
missing. Moreover, you should have this when using a Form and section is expandible:
protected final IExpansionListener expansionListener= new ExpansionAdapter()
{
/**
* {#inheritDoc}
*/
#Override
public void expansionStateChanged(ExpansionEvent e)
{
ScrolledForm form = ...; //your scrolled form goes here
form.layout(new Control[] {(ExpandableComposite) e.getSource()}, SWT.ALL | SWT.CHANGED);
form.reflow(true);
}
};
...
section.addExpansionListener(expansionListener);
Instead of the button test you should add a Composite which contains the button. Each section can have only one client.