Skip to Content
SWT: A Developer's Notebook
book

SWT: A Developer's Notebook

by Tim Hatton
October 2004
Intermediate to advanced
320 pages
7h 25m
English
O'Reilly Media, Inc.
Content preview from SWT: A Developer's Notebook

Creating Arrow Buttons

The final style attribute that you can apply to the Button class is SWT.ARROW. SWT.ARROW buttons, as the name implies, display an arrow graphic indicating the direction in which something that will occur when the button is pressed. SWT.ARROW style buttons also need to specify an additional style that determines in which direction the arrow graphic points. Possibilities are SWT.UP, SWT.DOWN, SWT.LEFT, and SWT.RIGHT.

A common use for arrow buttons is to enable the user to increment a value in an associated text box.

How do I do that?

Example 6-2 demonstrates how to use the SWT.ARROW button style in association with a Text field to permit the user to increment a value.

Example 6-2. Using SWT arrow buttons

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.*;
public class ArrowButtonExample {    
    Display d;
    Shell s;
    ArrowButtonExample( )    {
        d = new Display( );
        s = new Shell(d);
        s.setSize(250,250);
        s.setImage(new Image(d, "c:\\icons\\JavaCup.ico"));
        s.setText("A Button Example");
        final Button b1 = new Button(s, SWT.ARROW | SWT.UP);
        b1.setBounds(100,55,20,15);
        final Button b2 = new Button(s, SWT.ARROW | SWT.DOWN);
        b2.setBounds(100,70,20,15);
        final Text t1 = new Text(s, SWT.BORDER | SWT.SINGLE | SWT.CENTER);
        t1.setBounds(80, 55, 20, 30);
        t1.setText("1");
        t1.selectAll( );
        b1.addSelectionListener(new SelectionAdapter( ) {
            public ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Eclipse: Building Commercial-Quality Plug-ins, Second Edition

Eclipse: Building Commercial-Quality Plug-ins, Second Edition

Eric Clayberg, Dan Rubel
OSGi and Equinox

OSGi and Equinox

Jeff McAffer, Paul VanderLei, Simon Archer
Eclipse

Eclipse

Steve Holzner

Publisher Resources

ISBN: 0596008384Catalog PageErrata