Composite position and size - SWT - java

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'
}

Related

Eclipse SWT Group Empty

I'm Doing a Eclipse Plug-in which is a Multi-page-FormEditor.
On one Page i want some Data to be presented in Tables and Trees.
I want to split the Page vertical in to half's.
In order to achieve this i wanted to use Groups(Left Group,Right Group).
public class UtilityPage extends FormPage {
public UtilityPage(FormEditor editor, String id, String title) {
super(editor, id, title);
// TODO Auto-generated constructor stub
}
#Override
protected void createFormContent(IManagedForm managedForm) {
ScrolledForm scrolledForm = managedForm.getForm();
FormToolkit toolkit = managedForm.getToolkit();
Composite body = scrolledForm.getBody();
GridLayout layout = new GridLayout();
body.setLayout(layout);
layout.makeColumnsEqualWidth = true;
layout.numColumns = 2;
Group leftGroup = new Group(body, SWT.SHADOW_IN);
Group rightGroup = new Group(body, SWT.SHADOW_IN);
leftGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
rightGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
Label testLabel = new Label(rightGroup, SWT.CENTER);
testLabel.setText("<Test>");
Label testLabel2 = new Label(leftGroup, SWT.CENTER);
testLabel2.setText("<Test>");
leftGroup.pack();
rightGroup.pack();
}
}
My Problem is that this results in two Empty Groups without any Content.
https://i.imgur.com/5B7sXqS.png
This has happened to me multiple Times before, but i always worked around it.
But since i got no better idea how to accomplish my desired Layout, im here to ask if you guys have any other ideas. Or if you know what im doing wrong.
Since Group extends Composite you must set a layout on the group.
Something like:
Group leftGroup = new Group(body, SWT.SHADOW_IN);
leftGroup.setLayout(new GridLayout());
Group rightGroup = new Group(body, SWT.SHADOW_IN);
rightGroup.setLayout(new GridLayout());
When using layouts every Composite should have a layout. This includes classes such as Group which extend Composite.

java composite with an scrolling image

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;
}

Setting a JFreeChart ChartComposite to a fixed size in SWT

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.

Can I put a view into CTabFolder SWT?

As the title, I want to know that is there any way to put a view that extend ViewPart into a CtabFolder?
I have did some google search but there is nothing can help. So I decided to bring my question to here.
Thanks.
After tried more research I have found how to show a ViewPart in a CTabFolder as CTabItem. Here is it:
// create a container for the View part with tabFolder as a parent CTabFolder
Composite composite = new Composite(tabFolder, SWT.NONE);
composite.setLayout(new FillLayout());
CTabItem item = null;
item = new CTabItem(tabFolder, SWT.NONE);
// Create the one of the ViewPart I want to show in my CTabFolder
ProjectVersionDriversView myTestViewer = new ProjectVersionDriversView();
// call the init method on the ViewPart with the current ViewSite
try {
myTestViewer.init(this.getViewSite());
} catch (PartInitException e) {
e.printStackTrace();
}
// Build the ViewPart within our composite container.
myTestViewer.createPartControl(composite);
item.setText("Your Title");
// set the composite containing the view part as the control for tabItem2.
item.setControl(composite);
It's from here.

No Scroll on View in Eclipse RCP

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

Categories