I am facing some problems with JTextPane.
1. I am able to insert components(say JLabels) into JTextPane using insertComponent() method. When I press delete button or backspace button they are getting deleted. But when I select a region on JTextPane which contains 3-4 JLabels, and press some key; the text in the selected region is deleted but not the labels. How can I delete the JLabels in a selected region? How can I determine whether a component is within the selected region or not?
I have tried with setComponent() method also instead of insertComponent(). But the problem is the same.
Following is the code I wrote to remove components in selected region. But it is not working?
public void keyPressed(KeyEvent e)
char c = e.getKeyChar();
if(c == KeyEvent.VK_BACK_SPACE)
int start = m_txpEditor.getSelectionStart();
int end = m_txpEditor.getSelectionEnd();
System.out.println("Selected area being read");
System.out.println(start + ";" + end);
if(start == end)
//System.out.println("in for " + i);
AttributeSet as = m_txpEditor.getCharacterAttributes();
if((StyleConstants.getComponent(as)) != null)
comp = (JLabel)StyleConstants.getComponent(as);
}//end of keyPressed()
2. How can I implement bulleted lists(ordered, unordered) using JTextPane as in MS-Word?
Please provide suitable examples in your answers.
Thanks in advance.