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;
}
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'm developing a plugin for eclipse and I'm struggling to use ScrolledComposite as well as making it take up the remaining space.
The parent layout is a 2-column Grid:
#Override
public void createPartControl(Composite parent) {
parent.setLayout(new GridLayout(2, false));
// other views etc
}
The ScrolledComposite is created like so (slightly abbreviated):
private void fillScroll() {
if (scroll != null) {
scroll.dispose();
}
scroll = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
GridData gd = new GridData();
gd.horizontalSpan = 2;
scroll.setLayoutData(gd);
Composite innerContainer = new Composite(scroll, 0);
innerContainer.setLayout(new GridLayout(1, false));
// for loop that adds widgets to innerContainer
scroll.setExpandHorizontal(true);
scroll.setExpandVertical(true);
scroll.setContent(innerContainer);
scroll.setSize(innerContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT));
parent.layout(true);
}
The list of questions are the widgets added in the for loop and are contained by innerContainer.
Expectation: Since innerContainer is too large to fit in the parent, there should be scroll bars.
What actually happens: There are no scroll bars.
How do I fix this problem?
The GridData on the ScrolledComposite needs to have grabExcessVerticalSpace set to true. I suggest you to use the extended constructor in order to clearly define how it should be displayed, for example:
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
Option A: change scroll.setSize to scroll.setMinSize:
scroll.setMinSize(innerContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT));
or, Option B: remove scroll.setExpandHorizontal and scroll.setExpandVertical and change scroll.setSize to innerContainer.setSize:
innerContainer.setSize(innerContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT));
I'm trying to put a ScrolledComposite on my UI with SWT.
but now it only shows blank area or something wrong.
The area to show ScrolledComposite is blank without the code,
"optionCompositeAtLeft.setSize(optionCompositeAtLeft.computeSize(SWT.DEFAULT, SWT.DEFAULT)); "
This is the pic of screenshot.
The optionTab should have the buttons with Scroll....
and with the code, it shows scroll, but too long height and narrow width.
Somehow, the upper is gone, but come back when I extend the size of window with scroll disappearing.
I set the color of background red to make it easier to see for you.
Can anyone help me make "optionCompositeAtLeft" filled in ScrolledComposite?
I want the left area of Option tab to be filled with a red background from "optionCompositeAtLef".
Below is my code.
private BomCloneDialog dialog = null;
private TabFolder tabFolder = null;
private TabItem tabOption = null;
public CreateOptionTab(TabFolder tabFolder, TabItem tabOption) {
this.tabFolder = tabFolder;
this.tabOption = tabOption;
}
public void createOptionTabUI() {
GridData gdWithFillBoth = new GridData(GridData.FILL_BOTH);
Composite optionComposite = new Composite(tabFolder, SWT.NONE);
optionComposite.setLayout(new GridLayout(2, true));
tabOption.setControl(optionComposite);
ScrolledComposite scrolledCompositeForOption = new ScrolledComposite(optionComposite,SWT.V_SCROLL | SWT.BORDER);
scrolledCompositeForOption.setLayoutData(gdWithFillBoth);
Composite optionCompositeAtLeft = new Composite(scrolledCompositeForOption, SWT.BORDER);
scrolledCompositeForOption.setContent(optionCompositeAtLeft);
optionCompositeAtLeft.setLayout(new GridLayout(1, true));
optionCompositeAtLeft.setLayoutData(gdWithFillBoth);
optionCompositeAtLeft.setBackground(new Color(Display.getCurrent(), 255,0,0));
Button b [] = new Button[30];
for(int a=0; a<30; a++){
b[a] = new Button(optionCompositeAtLeft, SWT.PUSH);
b[a].setText("button"+a);
}
**optionCompositeAtLeft.setSize(optionCompositeAtLeft.computeSize(SWT.DEFAULT, SWT.DEFAULT));**
Composite optionButtonComposite = new Composite(optionComposite, SWT.BORDER);
optionButtonComposite.setLayout(new GridLayout(1, true));
optionButtonComposite.setLayoutData(gdWithFillBoth);
Button optionSaveButton = new Button(optionButtonComposite, SWT.NONE);
optionSaveButton.setLayoutData(gdWithFillBoth);
optionSaveButton.setText("Save");
Button optionAddButton = new Button(optionButtonComposite, SWT.NONE);
optionAddButton.setLayoutData(gdWithFillBoth);
optionAddButton.setText("Add");
}
You need to configure ScrolledComposite to resize the content:
scrolledCompositeForOption.setExpandHorizontal(true);
scrolledCompositeForOption.setExpandVertical(true);
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
Given the default container given to me from an Eclipse View, I wish to orient an AWT frame and an SWT Label. I want the SWT Label to be on the top, and the AWT Frame to be directly below it. For some reason, I cannot get the SWT Label to draw outside of where the frame is. I want them to be separate, yet the RowLayout doesn't appear to be putting the components into isolated rows.
SWT Label undesirably being placed inside of the AWT Frame:
Code within the Plugin's View:
public void createPartControl(Composite parent) {
container = new Composite(parent, SWT.EMBEDDED | SWT.NO_BACKGROUND);
RowLayout rowLayout = new RowLayout();
//I have tried toggling many of the RowLayout properties but this has no effect on placing the label outside of the AWT Frame.
container.setLayout(rowLayout);
Label topLabel = new Label(container, SWT.NONE);
topLabel.setText("MY NEW LABEL");
frame = org.eclipse.swt.awt.SWT_AWT.new_Frame(container);
frame.setFocusable(true);
frame.setFocusableWindowState(true);
RowLayout never puts components into separate rows, it puts them into one row. You can create it with SWT.VERTICAL style so that the row goes from top to bottom instead of left to right. However, the screenshot is still incorrect. It may help to have the frame as the only child of its own composite:
container = new Composite(parent, SWT.NONE);
RowLayout rowLayout = new RowLayout(SWT.VERTICAL);
container.setLayout(rowLayout);
Label topLabel = new Label(container, SWT.NONE);
topLabel.setText("MY NEW LABEL");
Composite frameContainer = new Composite(container, SWT.EMBEDDED | SWT.NO_BACKGROUND);
frame = org.eclipse.swt.awt.SWT_AWT.new_Frame(frameContainer);
frame.setFocusable(true);
frame.setFocusableWindowState(true);