lemme put my source here -
public class XMLFormatter extends javax.swing.JFrame {
/** Creates new form XMLFormatter */
public XMLFormatter() {
initComponents();
jtaText.setCaretPosition(0);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
private void initComponents() {
jspText = new javax.swing.JScrollPane();
jtaText = new javax.swing.JTextArea();
jpnSouth = new javax.swing.JPanel();
jbtnFont = new javax.swing.JButton();
jbtnFormat = new javax.swing.JButton();
jtbnClose = new javax.swing.JButton();
setTitle("XMLFormatter");
setFont(new java.awt.Font("Dialog", 0, 11));
setIconImage(java.awt.Toolkit.getDefaultToolkit().createImage(XMLFormatter.class.getResource("xmlformatter.gif")));
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
}
public void windowActivated(java.awt.event.WindowEvent evt) {
formWindowActivated(evt);
}
});
/* prepare Horizontal ScrollBar */
com.eibus.tools.CustomScrollBar hScrollBar = new com.eibus.tools.CustomScrollBar();
hScrollBar.setScrollBarUI(new com.eibus.tools.CustomScrollBarUI());
hScrollBar.setUnitIncrement(10);
hScrollBar.setOrientation(javax.swing.JScrollBar.HORIZONTAL);
/* prepare Vertical ScrollBar */
com.eibus.tools.CustomScrollBar vScrollBar = new com.eibus.tools.CustomScrollBar();
vScrollBar.setScrollBarUI(new com.eibus.tools.CustomScrollBarUI());
vScrollBar.setUnitIncrement(10);
vScrollBar.setOrientation(javax.swing.JScrollBar.VERTICAL);
jspText.setHorizontalScrollBar(hScrollBar);
jspText.setVerticalScrollBar(vScrollBar);
jtaText.setFont(new java.awt.Font("Dialog", 0, 11));
jspText.setViewportView(jtaText);
getContentPane().add(jspText, java.awt.BorderLayout.CENTER);
jbtnFont.setFont(new java.awt.Font("Dialog", 0, 11));
jbtnFont.setText("Font");
jbtnFont.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jbtnFontActionPerformed(evt);
}
});
jpnSouth.add(jbtnFont);
jbtnFormat.setFont(new java.awt.Font("Dialog", 0, 11));
jbtnFormat.setText("Format");
jbtnFormat.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jbtnFormatActionPerformed(evt);
}
});
jpnSouth.add(jbtnFormat);
jtbnClose.setFont(new java.awt.Font("Dialog", 0, 11));
jtbnClose.setText("Exit");
jtbnClose.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jtbnCloseActionPerformed(evt);
}
});
jpnSouth.add(jtbnClose);
getContentPane().add(jpnSouth, java.awt.BorderLayout.SOUTH);
pack();
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
setSize(new java.awt.Dimension(550, 400));
setLocation((screenSize.width-550)/2,(screenSize.height-400)/2);
}
private void formWindowActivated(java.awt.event.WindowEvent evt) {
/* Sometimes the caret is not visible after minimizing the window, hence this is used */
javax.swing.text.DefaultCaret defaultCaret = new javax.swing.text.DefaultCaret();
defaultCaret.setVisible(true);
defaultCaret.setBlinkRate(400);
jtaText.setCaret(defaultCaret);
jtaText.setCaretPosition(jtaText.getText().length());
}
private void jbtnFontActionPerformed(java.awt.event.ActionEvent evt) {
FormatterFontDialog fntDialog = new FormatterFontDialog(this, true, jtaText.getFont());
fntDialog.show();
if (FormatterFontDialog.blnOk) {
java.awt.Font f = fntDialog.getFont();
jtaText.setFont(f);
FormatterFontDialog.blnOk = false;
fntDialog.dispose();
}
}
private void jtbnCloseActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
private void jbtnFormatActionPerformed(java.awt.event.ActionEvent evt) {
try{
SAXDocument saxDocument = new SAXDocument(jtaText.getText().getBytes());
jtaText.setText((new NiceDOMWriter(saxDocument)).toString());
}catch(Exception ex){
javax.swing.JOptionPane.showMessageDialog(this, ex.getMessage(), "Invalid XML", javax.swing.JOptionPane.ERROR_MESSAGE);
}
}
/** Exit the Application */
private void exitForm(java.awt.event.WindowEvent evt) {
System.exit(0);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
try{
javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName());
}catch(Exception ex) {}
new XMLFormatter().show();
}
// Variables declaration - do not modify
private javax.swing.JScrollPane jspText;
private javax.swing.JTextArea jtaText;
private javax.swing.JPanel jpnSouth;
private javax.swing.JButton jbtnFont;
private javax.swing.JButton jbtnFormat;
private javax.swing.JButton jtbnClose;
// End of variables declaration
}
Pls ignore the functionality of "Format/Font", but i don't c the reason for the Caret disappearing here .....
Thanx.