Scrolls doesn't scroll in SWT

Joined
Sep 10, 2008
Messages
2
Reaction score
0
Hello, I'm doing a program and I'm finishing its interface. In one window I have to show some photos and I need to scroll it. The problem is that I've put the scroll and it goes up & down but the window is always in the same position. I don't know how to solve it, please I need help.

I put the code below:

Menu_bar.java:

package interficie;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;

public class Menu_bar {

Shell shell;
Display display;

Menu_bar() {

display = new Display();
shell = new Shell(display);
shell.setText("The Vertex Coloring Algorithm");
shell.setSize(500, 600);

Menu menuBar = new Menu(shell, SWT.BAR);
MenuItem examples = new MenuItem(menuBar, SWT.CASCADE);
examples.setText("Ejemplos");
Menu FileExamples = new Menu(shell, SWT.DROP_DOWN);
examples.setMenu(FileExamples);
MenuItem selectExamples= new MenuItem(FileExamples, SWT.CASCADE);
selectExamples.setText("Elegir ejemplo");

selectExamples.addSelectionListener(new MenuItemListener());

shell.setMenuBar(menuBar);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}

class MenuItemListener extends SelectionAdapter {
public void widgetSelected(SelectionEvent event) {
if (((MenuItem) event.widget).getText().equals("Elegir ejemplo")) {
Choose2 choose2= new Choose2(shell);
}
}
}

public static void main(String[] argv) {
new Menu_bar();
}
}

Choose2.java (Here's the problem with the scroll bar):

package interficie;

import java.io.InputStream;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;

public class Choose2 extends Dialog {
public Choose2(Shell parent) {
super(parent);
initialize();
}

public void initialize() {
Shell parent = getParent();
final Shell dialog = new Shell(parent, SWT.DIALOG_TRIM
| SWT.APPLICATION_MODAL |SWT.BORDER | SWT.V_SCROLL);
dialog.setSize(500, 800);
dialog.setText("Elegir ejemplo");

// Declaramos el número de buttons que necesitaremos
Button[] radios = new Button[20];

GridLayout gridLayout = new GridLayout(3,true);
dialog.setLayout(gridLayout);

GridData gridData = new GridData(GridData.BEGINNING);
gridData.grabExcessHorizontalSpace = true;

Display display = parent.getDisplay();


// Insertamos imagen1
InputStream is1 = ClassLoader.getSystemClassLoader().getResourceAsStream("images/bondy-murty.bmp");
Image image1 = new Image(null, is1);
Label l1 = new Label (dialog, SWT.BEGINNING);
l1.setImage(image1);

// Insertamos imagen2
InputStream is2 = ClassLoader.getSystemClassLoader().getResourceAsStream("images/bondy-murty2.bmp");
Image image2 = new Image(null, is2);
Label l2 = new Label (dialog, SWT.BEGINNING);
l2.setImage(image2);

// Insertamos imagen3
InputStream is3 = ClassLoader.getSystemClassLoader().getResourceAsStream("images/bondy-murty3.bmp");
Image image3 = new Image(null, is3);
Label l3 = new Label (dialog, SWT.BEGINNING);
l3.setImage(image3);

// Insertamos radiobuttons
radios[0] = new Button(dialog, SWT.RADIO);
radios[0].setSelection(true);
radios[0].setText("bondy-murty");
radios[0].setBounds(10, 5, 75, 30);

radios[1] = new Button(dialog, SWT.RADIO);
radios[1].setText("bondy-murty2");
radios[1].setBounds(10, 30, 75, 30);

radios[2] = new Button(dialog, SWT.RADIO);
radios[2].setText("bondy-murty3");
radios[2].setBounds(10, 55, 75, 30);

// Ejecutamos la interfaz
dialog.open();
while (!dialog.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
}



Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top