Home » Eclipse Projects » Remote Application Platform (RAP) » Problems using ScrolledComposite
Problems using ScrolledComposite [message #82306] |
Thu, 10 April 2008 13:31  |
Eclipse User |
|
|
|
This is a multi-part message in MIME format.
--------------000009000600090701090603
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Hi!
I'm having some problems using a scrolled composite. I'm going to try
to explain it the best I can....
Currently I have a scrolled composite (SC). Inside this SC I've created
a main composite (MC) where I place several other composites. The number
of composites I place inside the MC is dynamic. Supposing I'm having 20
composites (that need scroll) the SC will adjust and create a vertical
bar for the scroll to de made. But in the next refresh if I have only 2
composites inside the MC (no scroll is needed in this case) the vertical
bar doesn't "disappear" as it should and stays with the same dimension
as if it were 20 composites in the SC. I'm doing the layout() to both MC
and SC but the vertical bar is not updated. Before doing the layout()
I'm setting the size of the MC to be coherent with the number of
composites that are inside it.
Another problem that I have is the following: when I have 20 composites
(is an example) inside the MC the vertical scrollbar does not scroll
through all composites. I have changed some height properties of the
composites (SC and MC) but did not resolved the problem also.
Please consider the code snippet that goes as attachment were these
problems can be seen. The example starts by creating 20 composites
inside the MC. By pressing button "Update" the application will generate
randomly (between 0 and 21) new composites replacing the existing ones.
You should be able to see the behaviour I'm talking about.
On my rap example the screen is called this way:
final Display display = PlatformUI.createDisplay();
final Shell s = new Shell(display, SWT.SHELL_TRIM);
s.setText("Welcome");
s.setBounds(10, 10, 640, 480);
s.setLayout(new FillLayout());
new WelcomeScreen(s, SWT.NONE);
s.layout();
s.open();
while (!s.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
I have no ideas of how to fix this and help would be much appreciated. :)
Thanks in advance
Hugo Ferreira
--------------000009000600090701090603
Content-Type: text/java;
name="WelcomeScreen.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="WelcomeScreen.java"
package testrap.test;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Random;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
public class WelcomeScreen extends Composite {
private static final int V_SIZE = 115;
private static final int V_SPACE = 5;
private static final int H_SIZE = 1245;
private static final int NUM_COLUMNS = 4;
final ScrolledComposite scrolledComposite;
final List<String> itemList;
final Calendar calendar;
private int itemsInList = 20;
public WelcomeScreen(Composite parent, int style) {
super(parent, style);
this.setLayout(new GridLayout());
Composite baseComposite = new Composite(this, SWT.NONE);
baseComposite.setLayout(new GridLayout());
final GridData compositeGD = new GridData(SWT.FILL, SWT.CENTER, true, false);
compositeGD.heightHint = 28;
baseComposite.setLayoutData(compositeGD);
Button b = new Button(baseComposite, SWT.NONE);
b.setText("Update");
b.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
System.out.println("Prev Items in list=" + itemsInList);
Random r = new Random();
itemsInList = r.nextInt(21);
System.out.println("Curr Items in list=" + itemsInList);
createItems();
}
});
this.scrolledComposite = new ScrolledComposite(this, SWT.BORDER | SWT.V_SCROLL);
this.scrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
this.scrolledComposite.setAlwaysShowScrollBars(true);
this.scrolledComposite.setLayout(new GridLayout());
calendar = GregorianCalendar.getInstance();
itemList = new ArrayList<String>(20);
for (int i = 0; i < itemsInList; i++) {
itemList.add("Item " + i);
}
this.createItems();
}
private void createItems() {
// Obtaining the composite where the boxes are drawn if it already
// exists.
Composite mainComposite = null;
if (scrolledComposite.getContent() != null) {
mainComposite = (Composite) scrolledComposite.getContent();
} else {
mainComposite = new Composite(this.scrolledComposite, SWT.NONE);
final GridLayout gridLayout = new GridLayout(4, true);
mainComposite.setLayout(gridLayout);
}
Control[] designControls = null;
if (mainComposite != null) {
designControls = mainComposite.getChildren();
}
// creating the items
itemList.clear();
for (int i = 0; i < itemsInList; i++) {
itemList.add("Item " + i);
}
if (itemList != null) {
int itemIndex = 0;
for (final String label : itemList) {
createItemBoxes(mainComposite, SWT.BORDER, label, designControls, itemIndex);
itemIndex++;
}
}
// This routine deletes the composites not necessary on the design
if (designControls != null && itemsInList < designControls.length) {
for (int i = (designControls.length - 1); i >= itemsInList; i--) {
designControls[i].dispose();
}
System.out.println("Deleted: " + (designControls.length - itemsInList));
}
// These lines re-dimension the main composite size according to the
// number of items
final int numLines = (int) Math.ceil((double) itemsInList / (double) NUM_COLUMNS);
mainComposite.setSize(H_SIZE, V_SPACE + (V_SIZE * numLines));
// The content must only be set when the composite is drawn for the first time.
// Afterwards the composite is only "refreshed".
if (this.scrolledComposite.getContent() == null) {
this.scrolledComposite.setContent(mainComposite);
} else {
mainComposite.layout();
this.scrolledComposite.layout();
}
}
private void createItemBoxes(final Composite composite, final int style, final String label,
final Control[] design, final int itemIndex) {
if (design != null && (itemIndex + 1) <= design.length) {
if (design[itemIndex] instanceof Item) {
((Item) design[itemIndex]).refreshContents(label);
}
} else {
new Item(composite, style, label);
}
}
class Item extends Composite {
private Label itemText;
private static final int HEIGHT = 150;
private static final int WIDTH = 110;
public Item(Composite parent, int style, String label) {
super(parent, style);
this.setLayoutData(new GridData(WIDTH, HEIGHT));
this.setLayout(new GridLayout());
final Button statusImageButton = new Button(this, SWT.BORDER);
statusImageButton.setLayoutData(new GridData(100, 100));
itemText = new Label(this, SWT.NONE);
itemText.setText(label);
}
private void refreshContents(final String label) {
itemText.setText(label);
this.layout();
}
}
}
--------------000009000600090701090603--
|
|
| | | |
Re: Problems using ScrolledComposite [message #83844 is a reply to message #83133] |
Mon, 21 April 2008 11:58   |
Eclipse User |
|
|
|
Originally posted by: fappel.innoopract.com
Hi,
as I mentioned earlier, the behavior of your snippet is the same in RWT
and in RAP, so it seems to be no 'RWT' problem. What does the
ScrolledComposite#getAlwaysShowScrollBars() method return?
Ciao
Frank
-----Ursprüngliche Nachricht-----
Von: Hugo Ferreira [mailto:hmmfer@gmail.com]
Bereitgestellt: Dienstag, 15. April 2008 19:42
Bereitgestellt in: eclipse.technology.rap
Unterhaltung: Problems using ScrolledComposite
Betreff: Re: Problems using ScrolledComposite
Hi,
sorry for the delay responding to your suggestions. The
suggestion given by Frank solved the problem that I had when I wanted to
scroll through all composites, just by adding .pack() on the end of the
createItems().
But the first problem that I had (the vertical scroll bar does not
update its height according to the number of elements in the MC
composite) I could not discover yet. :( I've tried Nikolai suggestion
but it still doesn't work. Any more suggestions? Please? :)
Thanks in advance,
Hugo Ferreira
Nikolai wrote:
> Hi Hugo,
>
> I have no ControlResized listener seen in your code. Maybe this (an
> example) helps:
>
>
> ((ScrolledComposite)top).setContent(compositeGround);
> ((ScrolledComposite)top).setMinSize(300, 400);
> ((ScrolledComposite)top).setExpandHorizontal(true);
> ((ScrolledComposite)top).setExpandVertical(true);
>
> compositeGround.addControlListener(new ControlListener() {
>
> public void controlMoved(ControlEvent e) {
> // TODO Auto-generated method stub
>
> }
>
> public void controlResized(ControlEvent e) {
> Rectangle r =
> ((ScrolledComposite)top).getClientArea();
>
> ((ScrolledComposite)top).setMinSize(compositeGround.computeS ize(r.widt
> h,
> SWT.DEFAULT));
>
> }});
>
> regards,
>
> Nikolai
>
|
|
| | |
Re: Problems using ScrolledComposite [message #85255 is a reply to message #84468] |
Mon, 28 April 2008 13:36  |
Eclipse User |
|
|
|
Hi,
your wild guest works had a significant improvement on the layout (the
bar disappears if the composite doesn't need a scroll), but is not
perfect yet (I known that perfection is sometimes difficult to attain :)
). Now if I have all the items designed (20) and then the update only
generates 10 then bar will have the same size has if it were 20.
This is the only situation that could be improved although its much,
much better now! If you (or anyone) still have some wild guest to say
feel free to do it. :)
Many thanks!
Hugo Ferreira
Frank Appel wrote:
> Hm,
>
> just a wild guess, what happens if you set the attribute
> alwaysShowScrollBars to false?
>
>
> Ciao
> Frank
>
>
> -----Ursprüngliche Nachricht-----
> Von: Hugo Ferreira [mailto:hmmfer@gmail.com]
> Bereitgestellt: Mittwoch, 23. April 2008 16:00
> Bereitgestellt in: eclipse.technology.rap
> Unterhaltung: Problems using ScrolledComposite
> Betreff: Re: Problems using ScrolledComposite
>
>
> Hi,
>
> the ScrolledComposite#getAlwaysShowScrollBars() method returns true when
> the composite is created and when an update is made.
>
> --
> Hugo
>
> Frank Appel wrote:
>> Hi,
>>
>> as I mentioned earlier, the behavior of your snippet is the same in
>> RWT and in RAP, so it seems to be no 'RWT' problem. What does the
>> ScrolledComposite#getAlwaysShowScrollBars() method return?
>>
>>
>> Ciao
>> Frank
>>
>
|
|
|
Goto Forum:
Current Time: Sun Aug 31 12:59:06 EDT 2025
Powered by FUDForum. Page generated in 0.06811 seconds
|