Java-GNOME 2.10 GNOME Tutorial
<<< Previous | Containers | Next >>>

# ScrolledWindow

A ScrolledWindow displays a portion of a larger window through a view with scrollbars. The user can use the scrollbars to view the entirety of the child window. Let's take a look at an example from TestGTK.

Example 5. TestGTK.java - ScrolledWindow

    	public void createScrolledWindows() {
    		final Dialog win = new Dialog();
    		win.setTitle("Scrolled Windows");
    		win.setDefaultSize(200, 200);

    		ScrolledWindow scrolled_window = new ScrolledWindow(null, null);
    		scrolled_window.setBorderWidth(10);
    		scrolled_window.setPolicy(PolicyType.AUTOMATIC, PolicyType.AUTOMATIC);
    		((Box) (win.getDialogLayout())).packStart(scrolled_window);
    		scrolled_window.show();

    		Table table = new Table(20, 20, true);
    		table.setRowSpacing(10);
    		table.setColumnSpacing(10);
    		scrolled_window.addWithViewport(table);
    		table.show();

    		for (int i = 0; i < 20; i++)
    			for (int j = 0; j < 20; j++) {
    				ToggleButton button =
    					new ToggleButton("button (" + i + "," + j + ")", false);
    				table.attach(button, i, i + 1, j, j + 1,
    					AttachOptions.EXPAND.or(AttachOptions.FILL),
    					AttachOptions.EXPAND.or(AttachOptions.FILL),
    					0, 0);
    				button.show();
    			}
    		Button button = new Button("close", false);
    		button.addListener(new ButtonListener() {
    			public void buttonEvent(ButtonEvent event) {
    				if (event.isOfType(ButtonEvent.Type.CLICK)) {
    					win.destroy();
    				}
    			}
    		});
    		((Box) win.getActionArea()).packStart(button, false, false, 10);
    		button.show();
    		win.show();
    		win.run();
    	}

<<< Previous | Home | Next >>>
Paned | Up | Notebook