Focus Traversal : Focus « SWT JFace Eclipse « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Class
8. Collections Data Structure
9. Data Type
10. Database SQL JDBC
11. Design Pattern
12. Development Class
13. EJB3
14. Email
15. Event
16. File Input Output
17. Game
18. Generics
19. GWT
20. Hibernate
21. I18N
22. J2EE
23. J2ME
24. JDK 6
25. JNDI LDAP
26. JPA
27. JSP
28. JSTL
29. Language Basics
30. Network Protocol
31. PDF RTF
32. Reflection
33. Regular Expressions
34. Scripting
35. Security
36. Servlets
37. Spring
38. Swing Components
39. Swing JFC
40. SWT JFace Eclipse
41. Threads
42. Tiny Application
43. Velocity
44. Web Services SOA
45. XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java » SWT JFace Eclipse » FocusScreenshots 
Focus Traversal
Focus Traversal

/******************************************************************************
 * Copyright (c) 1998, 2004 Jackwind Li Guojie
 * All right reserved. 
 
 * Created on Jan 24, 2004 10:22:42 PM by JACK
 * $Id$
 
 * visit: http://www.asprise.com/swt
 *****************************************************************************/


import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.TraverseEvent;
import org.eclipse.swt.events.TraverseListener;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Shell;

public class FocusTraversal {
  Display display = new Display();
  Shell shell = new Shell(display);

  public FocusTraversal() {
    init();

    shell.pack();
    shell.open();
    //textUser.forceFocus();

    // Set up the event loop.
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        // If no more entries in event queue
        display.sleep();
      }
    }

    display.dispose();
  }

  private void init() {
    shell.setLayout(new RowLayout());
    
    Composite composite1 = new Composite(shell, SWT.BORDER);
    composite1.setLayout(new RowLayout());
    composite1.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
    
    Button button1 = new Button(composite1, SWT.PUSH);
    button1.setText("Button1");
    
    List list = new List(composite1, SWT.MULTI | SWT.BORDER);
    list.setItems(new String[]{"Item-1""Item-2""Item-3"});
    

    Button radioButton1 = new Button(composite1, SWT.RADIO);
    radioButton1.setText("radio-1");
    Button radioButton2 = new Button(composite1, SWT.RADIO);
    radioButton2.setText("radio-2");
    
    Composite composite2 = new Composite(shell, SWT.BORDER);
    composite2.setLayout(new RowLayout());
    composite2.setBackground(display.getSystemColor(SWT.COLOR_GREEN));
    
    Button button2 = new Button(composite2, SWT.PUSH);
    button2.setText("Button2");
    
    final Canvas canvas = new Canvas(composite2, SWT.NULL);
    canvas.setSize(5050);
    canvas.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));

    Combo combo = new Combo(composite2, SWT.DROP_DOWN);
    combo.add("combo");
    combo.select(0);
    
    canvas.addKeyListener(new KeyListener() {
      public void keyPressed(KeyEvent e) {
        GC gc = new GC(canvas);
        // Erase background first. 
        Rectangle rect = canvas.getClientArea();
        gc.fillRectangle(rect.x, rect.y, rect.width, rect.height);
        
        Font font = new Font(display, "Arial"32, SWT.BOLD );
        gc.setFont(font);
        
        gc.drawString("" + e.character, 1510);
        
        gc.dispose();
        font.dispose();
      }

      public void keyReleased(KeyEvent e) {
      }
    });
    
    canvas.addTraverseListener(new TraverseListener() {
      public void keyTraversed(TraverseEvent e) {
        if(e.detail == SWT.TRAVERSE_TAB_NEXT ||
            e.detail == SWT.TRAVERSE_TAB_PREVIOUS)
          e.doit = true;
      }
    });
    
    composite1.setTabList(new Control[]{button1, list});
    composite2.setTabList(new Control[]{button2, canvas, combo});
    
    shell.setTabList(new Control[]{composite2, composite1});
  }

  public static void main(String[] args) {
    new FocusTraversal();
  }
}



           
       
Related examples in the same category
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.