Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bullet list in JTextPane

Status
Not open for further replies.

borbjo

Programmer
Mar 29, 2002
33
0
0
NO
Anyone have links to info about implementing bullets in JTextPane (DefaultStyledDocument).

Or hints? :)
 
Code:
import java.io.*; 
import java.awt.*; 
import java.net.*; 
import javax.swing.*; 
import javax.swing.event.*; 
import javax.swing.text.*; 
public class myPan extends JPanel implements HyperlinkListener { 
    protected JEditorPane html; 
    URL url;

    public myPan() { 
        setLayout(new BorderLayout()); 

            html=new JEditorPane("text/html","");
html.setText(&quot;<html><head></head><body><a href=[URL unfurl="true"]http://www.yahoo.com>click[/URL] to go to yahoo</a><li>Hello</li></body></html>&quot;);
            html.setEditable(false); 
            html.addHyperlinkListener(this); 
            JScrollPane scroller = new JScrollPane(); 
            JViewport vp = scroller.getViewport(); 
            vp.add(html); 
            vp.setBackingStoreEnabled(true); 
           add(scroller, BorderLayout.CENTER);

    } 

    public void hyperlinkUpdate(HyperlinkEvent e) { 
        if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { 
            linkActivated(e.getURL()); 
        } 
    } 

    protected void linkActivated(URL u) { 
        Cursor c = html.getCursor(); 
        Cursor waitCursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR); 
        html.setCursor(waitCursor); 
        SwingUtilities.invokeLater(new PageLoader(u, c)); 
    } 

    class PageLoader implements Runnable { 
        URL url; 
        Cursor cursor; 

        PageLoader(URL u, Cursor c) { 
            url = u; 
            cursor = c; 
        } 
        public void run() { 
            if (url == null) { 
                html.setCursor(cursor); 
                Container parent = html.getParent(); 
                parent.repaint(); 
            } else { 
                Document doc = html.getDocument(); 
                try { 
                    html.setPage(url); 
                } catch (IOException ioe) { 
                    html.setDocument(doc); 
                    getToolkit().beep(); 
                } finally { 
                    url = null; 
                    SwingUtilities.invokeLater(this); 
                } 
            } 
        } 
    } 

    public static void main(String args[]) { 
        JFrame frame = new JFrame(&quot;Roadster&quot;); 
        myPan panel = new myPan(); 

        frame.getContentPane().add(panel); 
        frame.setSize(500, 300); 
        frame.setVisible(true); 
    } 
} 

/code]
 
Thanks, but I need to do it in a JTextPane in combination with a StyledDocument...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top