Text Tab Sample : Document HTML : Development Class : Java examples (example source code) Organized by topic

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Collections Data Structure
8. Database SQL JDBC
9. Design Pattern
10. Development Class
11. Email
12. Event
13. File Input Output
14. Game
15. Hibernate
16. J2EE
17. J2ME
18. JSP
19. JSTL
20. Language Basics
21. Network Protocol
22. PDF RTF
23. Regular Expressions
24. Security
25. Servlets
26. Spring
27. Swing Components
28. Swing JFC
29. SWT JFace Eclipse
30. Threads
31. Tiny Application
32. Velocity
33. XML
Java Tutorial
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Java » Development Class » Document HTMLScreenshots 
Text Tab Sample
Text Tab Sample

/*
Definitive Guide to Swing for Java 2, Second Edition
By John Zukowski     
ISBN: 1-893115-78-X
Publisher: APress
*/

import java.awt.BorderLayout;
import java.awt.Container;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultStyledDocument;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;
import javax.swing.text.TabSet;
import javax.swing.text.TabStop;

public class TextTabSample {
  public static void main(String args[]) {
    JFrame frame = new JFrame("Tab Attributes");
    Container content = frame.getContentPane();

    StyledDocument document = new DefaultStyledDocument();

    int positions[] TabStop.ALIGN_BAR, TabStop.ALIGN_CENTER,
        TabStop.ALIGN_DECIMAL, TabStop.ALIGN_LEFT, TabStop.ALIGN_RIGHT };
    String strings[] "\tBAR\n""\tCENTER\n""\t3.14159265\n",
        "\tLEFT\n""\tRIGHT\n" };

    SimpleAttributeSet attributes = new SimpleAttributeSet();

    for (int i = 0, n = positions.length; i < n; i++) {
      TabStop tabstop = new TabStop(150, positions[i], TabStop.LEAD_DOTS);
      try {
        int position = document.getLength();
        document.insertString(position, strings[i]null);
        TabSet tabset = new TabSet(new TabStop[] { tabstop });
        StyleConstants.setTabSet(attributes, tabset);
        document.setParagraphAttributes(position, 1, attributes, false);
      catch (BadLocationException badLocationException) {
        System.err.println("Oops");
      }
    }

    JTextPane textPane = new JTextPane(document);
    textPane.setEditable(false);
    JScrollPane scrollPane = new JScrollPane(textPane);
    content.add(scrollPane, BorderLayout.CENTER);

    frame.setSize(300150);
    frame.setVisible(true);
  }
}

           
       
Related examples in the same category
1. HTMLDocument: Element Iterator Example
2. HTMLEditorKit DemoHTMLEditorKit Demo
3. SimpleAttributeSet ExampleSimpleAttributeSet Example
4. Styled DocumentStyled Document
Home | Contact Us
Copyright 2003 - 07 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.