Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

JTextPane Problem

  Asked By: Annie    Date: Jun 28    Category: Java    Views: 465
  

i am trying to insert { text,Component, and
graphics} in JTextPane on the button's ActionListener. but there is
an exception that is

Exception occurred during event dispatching:
java.lang.ArrayIndexOutOfBoundsException at
javax.swing.SizeRequirements.calculateAlignedPositions
(SizeRequirements.java:338) at
javax.swing.OverlayLayout.layoutContainer(OverlayLayout.java:207)
at java.awt.Container.layout(Container.java:686) at
java.awt.Container.doLayout(Container.java:676) at
java.awt.Container.validateTree(Container.java:750) at
java.awt.Container.validateTree(Container.java:757) at
java.awt.Container.validateTree(Container.java:757) at
java.awt.Container.validateTree(Container.java:757) at
java.awt.Container.validate(Container.java:728) at
javax.swing.JViewport.validateView(JViewport.java:440) at
javax.swing.JViewport.scrollRectToVisible(JViewport.java:331) at
javax.swing.JComponent.scrollRectToVisible(JComponent.java:2322)
at javax.swing.text.DefaultCaret$SafeScroller.run
(DefaultCaret.java:1008) at
java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:154)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:317)
at java.awt.EventDispatchThread.pumpOneEvent
(EventDispatchThread.java:103) at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run
(EventDispatchThread.java:84) Process Exit...

i don't know why it is occuring. and it is not catches in the try
catch block

please solve my this problem

My Program code is:

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.text.*;

public class TextPaneChecking implements ActionListener
{
private JTextPane txtpane;
private Container container;
private SimpleAttributeSet set;
public TextPaneChecking()
{
set = new SimpleAttributeSet();
JFrame frm = new JFrame();
container = frm.getContentPane();

txtpane = new JTextPane();
container.add(new JScrollPane(txtpane));

JButton insert = new JButton("Insert");
insert.addActionListener(this);
container.add(insert,BorderLayout.SOUTH);
frm.setDefaultCloseOperation(frm.EXIT_ON_CLOSE);
frm.setSize(600,500);
frm.show();
}
public static void main(String args[])
{
new TextPaneChecking();
}
public void actionPerformed(ActionEvent e)
{
setText("Never ever thought about those things that
can never be in ur way");
newLine();
endSelection();

JPanel panel = new JPanel(new GridLayout(5,2,5,5));
panel.add(new JLabel("Please Enter Your Name "));
panel.add(new JTextField(50));
panel.add(new JLabel("Please Enter Your Father
Name "));
panel.add(new JTextField(50));
panel.add(new JLabel("Please Enter Your Address "));
panel.add(new JTextField(50));
panel.add(new JLabel("Please Enter Your Phone
No: "));
panel.add(new JTextField(50));
panel.add(new JLabel(""));
panel.add(new JButton("Submit"));

endSelection();
txtpane.insertComponent(panel);
newLine();
}
private void setText(String txt)
{
try
{
StyleConstants.setBold(set,true);
txtpane.getDocument().insertString
(txtpane.getDocument().getLength(),txt,set);
}
catch(Exception e)
{
}
}
private void newLine()
{
try
{
txtpane.getDocument().insertString
(txtpane.getDocument().getLength(),"\n",set);
}
catch(Exception e)
{
}
}
private void endSelection()
{
txtpane.setSelectionStart(txtpane.getDocument
().getLength());
txtpane.setSelectionEnd(txtpane.getDocument
().getLength());
}
}

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on JTextPane Problem Or get search suggestion and latest updates.




Tagged: