 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Daniel Forster Guest
|
Posted: Thu Jun 24, 2004 3:57 pm Post subject: problem with insertComponent |
|
|
does someone know, why this simple program does not work???
each time it detects ".*", this should be replaced by a button.
insertcomponent doesn't work. i tried with invokeLater and invokeAndWait -
nothing worked.
import java.awt.*;
import javax.swing.text.*;
import javax.swing.event.*;
import javax.swing.text.rtf.*;
import javax.swing.*;
class DF extends DocumentFilter {
JTextPane tp;
static boolean exit=false;
public DF(JTextPane t) {
tp=t;
}
public void replace(DocumentFilter.FilterBypass fb,int offset,int
length,String text,AttributeSet attr) throws BadLocationException {
if (exit) return;
fb.replace(offset,length,text,attr);
String pt=fb.getDocument().getText(0,fb.getDocument().getLength());
for (int x=1;x
if ((pt.charAt(x)=='*')&&(pt.charAt(x-1)=='.')) {
exit=true;
tp.select(x-1,x+1);
tp.insertComponent(new JButton("Click Me"));
exit=false;
}
}
}
public class Uni extends JFrame {
protected JTextPane m_monitor;
DefaultStyledDocument m_doc;
public Uni() {
m_monitor=new JTextPane();
RTFEditorKit m_kit=new RTFEditorKit();
m_monitor.setEditorKit(m_kit);
StyleContext m_context=new StyleContext();
m_doc=new DefaultStyledDocument(m_context);
m_monitor.setDocument(m_doc);
getContentPane().add(m_monitor,BorderLayout.CENTER);
((AbstractDocument)m_monitor.getDocument()).setDocumentFilter(new
DF(m_monitor));
m_monitor.replaceSelection(" .* - * - .* * * ");
setSize(600,400);
setVisible(true);
}
public static void main(String[] args) {
Uni u=new Uni();
}
}
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|