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.
Related
I have a composite, which has 3 UI controls - SWT Group, SWT TabFolder, and a child composite that has a label and a link. In some use-cases the SWT Group is hidden, and I would like that the blank space is not seen instead the composite has to be redrawn and show only the SWT TabFolder and the child composite, without any space.
I'm using composite.layout(true), but still there is blank space of the SWT Group when it is made hidden.
Could someone help me solve this issue
TestComposite extends Composite{
private Label childlabel;
private Group group;
private TabFolder tabFolder;
private Button button;
TestComposite(Compossite parent){
super(parent, SWT.NONE);
setLayout(new GridLayout(1, true));
setFont(parent.getFont());
setBackground(parent.getBackground());
GridDataFactory.fillDefaults().grab(true, true).applyTo(this);
createControl();
}
public void createControl() {
this.group = new Group(this, SWT.SHADOW_IN);
this.group.setSize(this.getDisplay().getActiveShell().getSize());
this.button = new Button(this.group, SWT.PUSH);
GridDataFactory.swtDefaults().applyTo(this.button);
this.tabFolder = new TabFolder(this, SWT.TOP);
GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL).grab(true,
true).applyTo(this.tabFolder);
Composite childComposite = new Composite(this, SWT.NONE);
childComposite .setLayout(new GridLayout(2, false));
GridDataFactory.swtDefaults().grab(true, false).align(SWT.LEFT,
SWT.TOP).applyTo(childComposite );
this.childLabel = new Label(childComposite, SWT.NONE);
GridDataFactory.swtDefaults().grab(true, false).applyTo(childlabel);
setInput(abc);
enableVisibilityOfGroup(false);
}
public void enableVisibilityOfGroup(Boolean visible){
this.group.setVisible(visible);
// this shoudl redraw the UI and shown only tabFolder and label in the
// whole wizard page, but there is blank space in place of group
this.layout(true);
}
}
Set GridData on the Group
GridDataFactory.swtDefaults().applyTo(this.group);
Use GridData.exclude to exclude/include the group in the layout:
public void enableVisibilityOfGroup(boolean visible) {
this.group.setVisible(visible);
GridData gridData = (GridData)this.group.getLayoutData();
gridData.exclude = !visible;
this.layout(true);
}
I am trying to create some content for tabItems. I created methods to create each tab. For example:
private static void initSolutionsTab (TabFolder folder){
TabItem solutions = new TabItem(folder, SWT.NONE);
solutions.setText("Solutions");
Composite solutionTop = new Composite(folder, SWT.NONE);
ScrolledComposite topScroller = new ScrolledComposite(solutionTop, SWT.V_SCROLL);
//Should later hold many groups
Composite groupHolder = new Composite(topScroller,SWT.NONE);
Group solutionsGroup = new Group(groupHolder, SWT.BORDER_DOT);
Label solutionLabel = new Label(solutionsGroup, SWT.NONE);
solutionLabel.setText("TEST");
topScroller.setContent(groupHolder);
solutions.setControl(solutionTop);
}
But it is just showing a blank space in the tab. I am missing (or not understanding) something, I know, but I just don't find the mistake.
Can somebody please give me a hint?
try to use setSize() for your TabFolder
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 designing a GUI in jface/swt,in which I am creating a scrolledform which contains a section and inside that section there is a composite.
On that composite,i am adding a comboviewer which has 2 elements.
on selecting first element, there are 2 widgets, one is label with textbox and other is table.
On selecting second element, there is only one widget that is label with textbox.
Now,my problem is that when i am selecting second element it is disposing the table but the space occupied by table is remain there.
so,how to remove that unwanted space after selecting seconnd element.
Please help me out.
Here is my first function in which i am creating scrolled form
class Test extends FormDialog{
protected void createFormContent(IManagedForm managedform) {
toolkit = managedform.getToolkit();
scrolledForm = managedform.getForm();
Shell shell = scrolledForm.getShell();
shell.setText("First Form");
// I am using GridLayout and GridData.
scrolledForm.pack();
scrolledForm.reflow(true);
}
// After this there is a method containing section and a composite inside the section.
protected void createCombo(final Composite client) {
Label label1 = toolkit.createLabel(client,"First Label : ", SWT.NULL);
final ComboViewer comboViewer1 = new ComboViewer(client,SWT.NORMAL|SWT.NORMAL);
//In this Compoviewer1, I am adding 2 persons ie "ABC" and "XYZ".
comboViewer1.getCombo().select(0);
// Here I am Calling Two methods, createFirstContent() method contains label and comboviewer. And createSecondContent() method contains TableViewer which is created inside a Group
createFirstContent(client);
createSecondContent(client);
comboViewer1.addSelectionChangedListener(new ISelectionChangedListener(){
#Override
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection selection = (IStructuredSelection) event
.getSelection();
if(((Person) selection.getFirstElement()).getName().equals("ABC")){
createFirstContent(client);
createSecondContent(client);
}else if(((Person) selection.getFirstElement()).getName().equals("XYZ")){
if(tablegroup != null && !(tablegroup.isDisposed())){
tablegroup.dispose();
createFirstContent(client);
}
});
}
protected void createFirstContent(Composite clientComposite){
Label label = toolkit.createLabel(clientComposite,"First Lbl : ", SWT.NULL);
label .setLayoutData(new GridData(SWT.FILL, SWT.FILL,true, false));
ComboViewer combo = new ComboViewer(clientComposite, SWT.READ_ONLY | SWT.NORMAL);
}
protected void createSecondContent(Composite clientComposite) {
tablegroup = new Group(clientComposite, SWT.FILL);
tablegroup.setLayout(new GridLayout());
tablegroup.setText("Table Group");
createTableViewer(tablegroup);
GridData gridData = new GridData();
gridData.verticalAlignment = GridData.FILL;
gridData.horizontalSpan = 2;
gridData.grabExcessHorizontalSpace = false;
gridData.grabExcessVerticalSpace = true;
gridData.horizontalAlignment = GridData.FILL;
tablegroup.setLayoutData(gridData);
}
protected void createTableViewer(Group tablegroup) {
viewer = new TableViewer(tablegroup, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
TableColumnLayout tcl = new TableColumnLayout();
createColumns(tcl);
final Table table = viewer.getTable();
table.setHeaderVisible(true);
table.setLinesVisible(true);
GridData gridData = new GridData(SWT.FILL, SWT.FILL,true, true;
gridData.horizontalSpan = 2;
viewer.getControl().setLayoutData(gridData);
}
In the createColums() method, i am creating the columns of table.
After all these things, i am creating another section.and creating some other widgets in that section.
but my problem is that when i am disposing taht table while selecting XYZ, table will get disposed but the space occupied by table is not removing.
So, there will be an unwanted gap/space between both the sections.
Please tell me how to remove that space.
I am creating a custom tooltip where i have a textbox.I am able to do that but i could not get balloon like icon as in the attached picture .Can anyone help me regarding this.
Mytooltip class:
public class MyToolTip extends ToolTip {
private Shell parentShell;
public MyToolTip(Control control) {
super(control,SWT.BALLOON,false);
this.parentShell = control.getShell();
}
#Override
protected Composite createToolTipContentArea(Event event, Composite parent) {
// TODO Auto-generated method stub
Composite comp = new Composite(parent,SWT.NONE);
comp.setLayout(new FillLayout());
Text text = new Text(comp,SWT.BORDER);
text.setText("");
return comp;
}
}
Class using tooltip:
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new RowLayout(SWT.VERTICAL));
Text text = new Text(shell, SWT.BORDER);
text.setText("sample text field");
MyToolTip myTooltipLabel = new MyToolTip(text);
myTooltipLabel.setShift(new Point(-5, -5));
myTooltipLabel.setHideOnMouseDown(false);
myTooltipLabel.activate();
myTooltipLabel.setRespectDisplayBounds(false);
myTooltipLabel.setRespectMonitorBounds(false);
The problem is, that you are using org.eclipse.jface.window.ToolTip whereas the code that was used to create that screenshot uses org.eclipse.swt.widgets.ToolTip.
The SWT tooltip can have the balloon look by passing SWT.BALLOON as the style bit.
The JFace tooltip does not support SWT.BALLOON, only ToolTip.NO_RECREATE and ToolTip.RECREATE.
So here is the conclusion: You can't subclass the swt tooltip to make it editable. You can't make the JFace tooltip look the way you want it to look. The only solution that is left is creating your own Widget based on Composite or Canvas that does what you want.