Text Tab Sample : Document HTML « Development Class « Java

Home
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.JavaFX
25.JDK 6
26.JDK 7
27.JNDI LDAP
28.JPA
29.JSP
30.JSTL
31.Language Basics
32.Network Protocol
33.PDF RTF
34.Reflection
35.Regular Expressions
36.Scripting
37.Security
38.Servlets
39.Spring
40.Swing Components
41.Swing JFC
42.SWT JFace Eclipse
43.Threads
44.Tiny Application
45.Velocity
46.Web Services SOA
47.XML
Java » Development Class » Document HTML 




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
5.Html utils for working with tag's names and attributes.
6.Escape HTML
7.Escape HTML
8.Encode HTML
9.Replace all the occurences of HTML escape strings with the respective characters.
10.HTML Rewriter
11.HTML Encode
12.XMLWriter is a generic class that provides common behavior to writers of a tagged language such as XML, WordML and HTML.
13.Escape html entities.
14.Html Encoder
15.Remove Comment
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.