Scrolls doesn't scroll in SWT

Discussion in 'Java' started by barbara.morey, Sep 10, 2008.

  1. barbara.morey

    barbara.morey

    Joined:
    Sep 10, 2008
    Messages:
    2
    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
    barbara.morey, Sep 10, 2008
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?ZG90bmV0a3VtYXI=?=

    scrolls scrolls scrolls scrolls scrolls ...............

    =?Utf-8?B?ZG90bmV0a3VtYXI=?=, Aug 4, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    334
    =?Utf-8?B?ZG90bmV0a3VtYXI=?=
    Aug 4, 2005
  2. Noozer
    Replies:
    1
    Views:
    1,331
    Mark Parnell
    Jun 16, 2005
  3. luqman

    Page scrolls up on update ?

    luqman, Aug 13, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    310
    Masudur
    Aug 13, 2007
  4. Ramon F Herrera

    Where can I download SWT? (SWT homepage)

    Ramon F Herrera, Dec 5, 2007, in forum: Java
    Replies:
    11
    Views:
    4,008
    Ramon F Herrera
    Dec 6, 2007
  5. AAaron123

    View scrolls on post back

    AAaron123, Aug 7, 2008, in forum: ASP .Net
    Replies:
    2
    Views:
    331
    AAaron123
    Aug 7, 2008
Loading...

Share This Page