3 Replies - 5017 Views - Last Post: 26 April 2010 - 11:08 AM Rate Topic: -----

#1 dablackreaper  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 25-April 10

getText() returns null when refered with jTextPane

Posted 26 April 2010 - 02:10 AM

hello friends.

i am making an Email client which requires me to take input from a jTextPane and then putting it into a string and then sending it. i am using jTextPane.getText() to get the text and then adding it to a string to be sent.

string mytxt=jTextPane1.getText();
but on sending it..it returns null.there is no text sent even though the attachment is going. when i tried System.out.Println(jtextpane1.getText()); it did not return anything..
please tell me where i am going wrong.


here is the affected code
public class ComposeFinal extends javax.swing.JFrame {
   // private javax.swing.jTextPane JTextPane1(40,72);
    //private String host;
    private String userName;
    private String password;
    private String host;
  // private String mytxt;
   JTextPane jTextPane1 = new JTextPane();
    


    private Action openAction = new OpenAction();
    private Action saveAction = new SaveAction();
    SimpleAttributeSet attributes;
    String filepath[]=new String[2];
    // Message msg=null;
     private Hashtable actionHash = new Hashtable();
    /** Creates new form Compose */
    public ComposeFinal(String host,String username,String password) {
        this.host=host;
        this.userName = username;
        this.password = password;
        
        initComponents();
        attributes = new SimpleAttributeSet();
        setJMenuBar(createMenuBar());
        makeActionsPretty();
               Properties props = new Properties();
        Session session = Session.getInstance(props);
        Message msg = new MimeMessage(session);

       //String mytxt=jTextPane1.getText();



    }

   void actionSend()
    {
  //private void run() throws MessagingException {
   // String to = "[email protected]";
        String from = this.userName;
        // SUBSTITUTE YOUR ISP'S MAIL SERVER HERE!!!
        host = "smtp.bol.net.in";

        // Create properties for the Session
        Properties props = new Properties();

        // If using static Transport.send(),
        // need to specify the mail server here
        props.put("mail.smtp.host", host);
        // To see what is going on behind the scene
        props.put("mail.debug", "true");

        // Get a session
        Session session = Session.getInstance(props);

        try {
            // Get a Transport object to send e-mail
            Transport bus = session.getTransport("smtp");

            // Connect only once here
            // Transport.send() disconnects after each send
            // Usually, no username and password is required for SMTP
            //bus.connect();
            bus.connect(this.host, this.userName, this.password);

            // Instantiate a message
            Message msg = new MimeMessage(session);
            msg.setFrom(new InternetAddress(from));
            
            // Set message attributes
            String str=jTextField1.getText();
            String[] temp;
            String delimiter=",";
            temp=str.split(delimiter);
            for(int i=0;i<temp.length;i++)
            {
            InternetAddress[] address = {new InternetAddress(temp[i])};
            msg.setRecipients(Message.RecipientType.TO, address);
            msg.setSubject(jTextField4.getText());

            msg.setSentDate(new Date());

            // Set message content and send
           setTextContent(msg);
            msg.saveChanges();
            bus.sendMessage(msg, msg.getAllRecipients());

          setMultipartContent(msg);
            msg.saveChanges();
            bus.sendMessage(msg, msg.getAllRecipients());

            setFileAsAttachment(msg, jTextField5.getText());
            //msg.saveChanges();
            bus.sendMessage(msg,msg.getAllRecipients());

           // setHTMLContent(msg);
            msg.saveChanges();
           bus.sendMessage(msg, msg.getAllRecipients());
            }
            

          

            
         /*  // InternetAddress[] addressTo = new InternetAddress[jTextField1.getText()];
    //for (int i = 0; i < to.length; i++)
    //{
      //  addressTo[i] = new InternetAddress(to[i]);
    //}
    msg.setRecipients(Message.RecipientType.TO, addressTo);
         * */

            // Parse a comma-separated list of email addresses. Be strict.
            //InternetAddress[] address1 = {new InternetAddress(jTextField2.getText())};
          String str1=jTextField3.getText();
            String[] temp1;
            //String delimiter=",";
            temp1=str1.split(delimiter);
            for(int i=0;i<temp1.length;i++)
            
            {

                msg.setRecipients(Message.RecipientType.BCC,
                                InternetAddress.parse(temp1[i]));
                msg.setSubject(jTextField4.getText());

            msg.setSentDate(new Date());

            // Set message content and send
           setTextContent(msg);
            msg.saveChanges();
            bus.sendMessage(msg, msg.getAllRecipients());

          setMultipartContent(msg);
            msg.saveChanges();
            bus.sendMessage(msg, msg.getAllRecipients());

            setFileAsAttachment(msg, jTextField5.getText());
            //msg.saveChanges();
            bus.sendMessage(msg,msg.getAllRecipients());

           // setHTMLContent(msg);
            msg.saveChanges();
           bus.sendMessage(msg, msg.getAllRecipients());
            }

            // Parse comma/space-separated list. Cut some slack.
            String str2=jTextField2.getText();
            String[] temp2;
            //String delimiter=",";
            temp2=str.split(delimiter);
            for(int i=0;i<temp2.length;i++)

            {
            msg.setRecipients(Message.RecipientType.CC,
                                InternetAddress.parse(temp2[i]));
            msg.setSubject(jTextField4.getText());

            msg.setSentDate(new Date());

            // Set message content and send
           setTextContent(msg);
            msg.saveChanges();
            bus.sendMessage(msg, msg.getAllRecipients());

          setMultipartContent(msg);
            msg.saveChanges();
            bus.sendMessage(msg, msg.getAllRecipients());

            setFileAsAttachment(msg, jTextField5.getText());
            //msg.saveChanges();
            bus.sendMessage(msg,msg.getAllRecipients());

           // setHTMLContent(msg);
            msg.saveChanges();
           bus.sendMessage(msg, msg.getAllRecipients());
            
            }

System.out.println(jTextPane1.getText());
            
        
            bus.close();
            /*Folder folder = msg.getFolder();
            folder.close(true);
            folder.open(Folder.READ_WRITE); */

        }
        catch (MessagingException mex) {
            // Prints all nested (chained) exceptions as well
            mex.printStackTrace();
            // How to access nested exceptions
            while (mex.getNextException() != null) {
                // Get next exception in chain
                Exception ex = mex.getNextException();
                ex.printStackTrace();
                if (!(ex instanceof MessagingException)) break;
                else mex = (MessagingException)ex;
            }}

   }
    public void setTextContent(Message msg) throws MessagingException {
            // Set message content
    

            String mytxt=jTextPane1.getText();

            // ERROR HERE..IM FACING PROBLEM HERE.
            //  msg.setText(mytxt);

            // Alternate form
            msg.setContent(jTextPane1.getText(), "text/plain");

    }



    // A simple multipart/mixed e-mail. Both body parts are text/plain.
    public void setMultipartContent(Message msg) throws MessagingException {
        // Create and fill first part
        MimeBodyPart p1 = new MimeBodyPart();
        p1.setText(jTextPane1.getText());

        // Create and fill second part
        MimeBodyPart p2 = new MimeBodyPart();
        // Here is how to set a charset on textual content
        p2.setText("This is the second part", "us-ascii");

        // Create the Multipart.  Add BodyParts to it.
        Multipart mp = new MimeMultipart();
        mp.addBodyPart(p1);
        mp.addBodyPart(p2);

        // Set Multipart as the message's content
        msg.setContent(mp);
    }



    // Set a file as an attachment.  Uses JAF FileDataSource.
    public void setFileAsAttachment(Message msg, String filename)
             throws MessagingException {

        // Create and fill first part
        MimeBodyPart p1 = new MimeBodyPart();
        p1.setText(jTextPane1.getText());

        // Create second part
        MimeBodyPart p2 = new MimeBodyPart();

        // Put a file in the second part
        FileDataSource fds = new FileDataSource(filename);
        p2.setDataHandler(new DataHandler(fds));
        p2.setFileName(fds.getName());

        // Create the Multipart.  Add BodyParts to it.
        Multipart mp = new MimeMultipart();
        mp.addBodyPart(p1);
        mp.addBodyPart(p2);

        // Set Multipart as the message's content
        msg.setContent(mp);
    }






here is my complete code..

/*
 * Compose.java
 *
 * Created on February 21, 2006, 1:18 PM
 */

package my.MaxMailer1;

/**
 *
 * @author  Montu
 */

import java.util.Date;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMessage.RecipientType;
import javax.swing.*;
import javax.swing.text.*;
import javax.swing.event.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;
import javax.swing.JFileChooser;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;


public class ComposeFinal extends javax.swing.JFrame {
   // private javax.swing.jTextPane JTextPane1(40,72);
    //private String host;
    private String userName;
    private String password;
    private String host;
  // private String mytxt;
   JTextPane jTextPane1 = new JTextPane();
    


    private Action openAction = new OpenAction();
    private Action saveAction = new SaveAction();
    SimpleAttributeSet attributes;
    String filepath[]=new String[2];
    // Message msg=null;
     private Hashtable actionHash = new Hashtable();
    /** Creates new form Compose */
    public ComposeFinal(String host,String username,String password) {
        this.host=host;
        this.userName = username;
        this.password = password;
        
        initComponents();
        attributes = new SimpleAttributeSet();
        setJMenuBar(createMenuBar());
        makeActionsPretty();
               Properties props = new Properties();
        Session session = Session.getInstance(props);
        Message msg = new MimeMessage(session);

       //String mytxt=jTextPane1.getText();



    }

   void actionSend()
    {
  //private void run() throws MessagingException {
   // String to = "[email protected]";
        String from = this.userName;
        // SUBSTITUTE YOUR ISP'S MAIL SERVER HERE!!!
        host = "smtp.bol.net.in";

        // Create properties for the Session
        Properties props = new Properties();

        // If using static Transport.send(),
        // need to specify the mail server here
        props.put("mail.smtp.host", host);
        // To see what is going on behind the scene
        props.put("mail.debug", "true");

        // Get a session
        Session session = Session.getInstance(props);

        try {
            // Get a Transport object to send e-mail
            Transport bus = session.getTransport("smtp");

            // Connect only once here
            // Transport.send() disconnects after each send
            // Usually, no username and password is required for SMTP
            //bus.connect();
            bus.connect(this.host, this.userName, this.password);

            // Instantiate a message
            Message msg = new MimeMessage(session);
            msg.setFrom(new InternetAddress(from));
            
            // Set message attributes
            String str=jTextField1.getText();
            String[] temp;
            String delimiter=",";
            temp=str.split(delimiter);
            for(int i=0;i<temp.length;i++)
            {
            InternetAddress[] address = {new InternetAddress(temp[i])};
            msg.setRecipients(Message.RecipientType.TO, address);
            msg.setSubject(jTextField4.getText());

            msg.setSentDate(new Date());

            // Set message content and send
           setTextContent(msg);
            msg.saveChanges();
            bus.sendMessage(msg, msg.getAllRecipients());

          setMultipartContent(msg);
            msg.saveChanges();
            bus.sendMessage(msg, msg.getAllRecipients());

            setFileAsAttachment(msg, jTextField5.getText());
            //msg.saveChanges();
            bus.sendMessage(msg,msg.getAllRecipients());

           // setHTMLContent(msg);
            msg.saveChanges();
           bus.sendMessage(msg, msg.getAllRecipients());
            }
            

          

            
         /*  // InternetAddress[] addressTo = new InternetAddress[jTextField1.getText()];
    //for (int i = 0; i < to.length; i++)
    //{
      //  addressTo[i] = new InternetAddress(to[i]);
    //}
    msg.setRecipients(Message.RecipientType.TO, addressTo);
         * */

            // Parse a comma-separated list of email addresses. Be strict.
            //InternetAddress[] address1 = {new InternetAddress(jTextField2.getText())};
          String str1=jTextField3.getText();
            String[] temp1;
            //String delimiter=",";
            temp1=str1.split(delimiter);
            for(int i=0;i<temp1.length;i++)
            
            {

                msg.setRecipients(Message.RecipientType.BCC,
                                InternetAddress.parse(temp1[i]));
                msg.setSubject(jTextField4.getText());

            msg.setSentDate(new Date());

            // Set message content and send
           setTextContent(msg);
            msg.saveChanges();
            bus.sendMessage(msg, msg.getAllRecipients());

          setMultipartContent(msg);
            msg.saveChanges();
            bus.sendMessage(msg, msg.getAllRecipients());

            setFileAsAttachment(msg, jTextField5.getText());
            //msg.saveChanges();
            bus.sendMessage(msg,msg.getAllRecipients());

           // setHTMLContent(msg);
            msg.saveChanges();
           bus.sendMessage(msg, msg.getAllRecipients());
            }

            // Parse comma/space-separated list. Cut some slack.
            String str2=jTextField2.getText();
            String[] temp2;
            //String delimiter=",";
            temp2=str.split(delimiter);
            for(int i=0;i<temp2.length;i++)

            {
            msg.setRecipients(Message.RecipientType.CC,
                                InternetAddress.parse(temp2[i]));
            msg.setSubject(jTextField4.getText());

            msg.setSentDate(new Date());

            // Set message content and send
           setTextContent(msg);
            msg.saveChanges();
            bus.sendMessage(msg, msg.getAllRecipients());

          setMultipartContent(msg);
            msg.saveChanges();
            bus.sendMessage(msg, msg.getAllRecipients());

            setFileAsAttachment(msg, jTextField5.getText());
            //msg.saveChanges();
            bus.sendMessage(msg,msg.getAllRecipients());

           // setHTMLContent(msg);
            msg.saveChanges();
           bus.sendMessage(msg, msg.getAllRecipients());
            
            }

System.out.println(jTextPane1.getText());
            
        
            bus.close();
            /*Folder folder = msg.getFolder();
            folder.close(true);
            folder.open(Folder.READ_WRITE); */

        }
        catch (MessagingException mex) {
            // Prints all nested (chained) exceptions as well
            mex.printStackTrace();
            // How to access nested exceptions
            while (mex.getNextException() != null) {
                // Get next exception in chain
                Exception ex = mex.getNextException();
                ex.printStackTrace();
                if (!(ex instanceof MessagingException)) break;
                else mex = (MessagingException)ex;
            }}

   }
    public void setTextContent(Message msg) throws MessagingException {
            // Set message content
    

            String mytxt=jTextPane1.getText();

            // ERROR HERE..IM FACING PROBLEM HERE.
            //  msg.setText(mytxt);

            // Alternate form
            msg.setContent(jTextPane1.getText(), "text/plain");

    }



    // A simple multipart/mixed e-mail. Both body parts are text/plain.
    public void setMultipartContent(Message msg) throws MessagingException {
        // Create and fill first part
        MimeBodyPart p1 = new MimeBodyPart();
        p1.setText(jTextPane1.getText());

        // Create and fill second part
        MimeBodyPart p2 = new MimeBodyPart();
        // Here is how to set a charset on textual content
        p2.setText("This is the second part", "us-ascii");

        // Create the Multipart.  Add BodyParts to it.
        Multipart mp = new MimeMultipart();
        mp.addBodyPart(p1);
        mp.addBodyPart(p2);

        // Set Multipart as the message's content
        msg.setContent(mp);
    }



    // Set a file as an attachment.  Uses JAF FileDataSource.
    public void setFileAsAttachment(Message msg, String filename)
             throws MessagingException {

        // Create and fill first part
        MimeBodyPart p1 = new MimeBodyPart();
        p1.setText(jTextPane1.getText());

        // Create second part
        MimeBodyPart p2 = new MimeBodyPart();

        // Put a file in the second part
        FileDataSource fds = new FileDataSource(filename);
        p2.setDataHandler(new DataHandler(fds));
        p2.setFileName(fds.getName());

        // Create the Multipart.  Add BodyParts to it.
        Multipart mp = new MimeMultipart();
        mp.addBodyPart(p1);
        mp.addBodyPart(p2);

        // Set Multipart as the message's content
        msg.setContent(mp);
    }







    /** 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.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jTextField1 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();
        jTextField3 = new javax.swing.JTextField();
        jTextField4 = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jTextField5 = new javax.swing.JTextField();
        jButton4 = new javax.swing.JButton();
        jTextField6 = new javax.swing.JTextField();
        jButton6 = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        JTextPane jTextPane1 = new JTextPane();
        jToolBar1 = new javax.swing.JToolBar();
        jButton3 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JToolBar.Separator();
        jButton7 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        jButton9 = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JToolBar.Separator();
        jButton10 = new javax.swing.JButton();
        jButton11 = new javax.swing.JButton();
        jButton12 = new javax.swing.JButton();
        jSeparator3 = new javax.swing.JToolBar.Separator();
        jButton13 = new javax.swing.JButton();
        jButton14 = new javax.swing.JButton();
        jButton15 = new javax.swing.JButton();
        jSeparator4 = new javax.swing.JToolBar.Separator();
        //jComboBox2 = new javax.swing.JComboBox();
        jComboBox1 = new javax.swing.JComboBox();
        jComboBox3 = new javax.swing.JComboBox();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem4 = new javax.swing.JMenuItem();
        jMenuItem5 = new javax.swing.JMenuItem();
        jMenuItem6 = new javax.swing.JMenuItem();
        jMenuItem7 = new javax.swing.JMenuItem();


        jComboBox2= new JComboBox(new Object[] {
			    new Item(new Object[] { Color.gray, "gray" }),
                            new Item(new Object[] { Color.orange, "orange" }),
                            new Item(new Object[] { Color.red, "red" }),
                            new Item(new Object[] { Color.blue, "blue" }),
                            new Item(new Object[] { Color.yellow, "yellow" }),
                            new Item(new Object[] { Color.magenta, "magenta" }),
                            new Item(new Object[] { Color.black, "black" }),
                            new Item(new Object[] { Color.green, "green" }),
                            new Item(new Object[] { Color.lightGray, "lightGray"})
                            });
		jComboBox2.setRenderer(new ColorRenderer());
               //jComboBox2.setToolTipText("Text Color");
        jComboBox2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox2ActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 100, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 100, Short.MAX_VALUE)
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jTextField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
               // jTextField1ActionPerformed(evt);
            }
        });

        jTextField3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField3ActionPerformed(evt);
            }
        });

        jLabel1.setText("TO:");
        jLabel1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel1MouseClicked(evt);
            }
        });

        jLabel2.setText("Cc:");

        jLabel3.setText("Bcc");

        jLabel4.setText("Subject");

        org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .addContainerGap(34, Short.MAX_VALUE)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(jPanel2Layout.createSequentialGroup()
                        .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel2)
                            .add(jLabel1)
                            .add(jLabel3))
                        .add(28, 28, 28))
                    .add(jPanel2Layout.createSequentialGroup()
                        .add(jLabel4)
                        .add(18, 18, 18)))
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, jTextField1)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, jTextField4)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, jTextField3)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, jTextField2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 549, Short.MAX_VALUE))
                .addContainerGap(35, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel1))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 26, Short.MAX_VALUE)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jTextField2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel2))
                .add(15, 15, 15)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jTextField3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel3))
                .add(19, 19, 19)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jTextField4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel4)))
        );

        jButton1.setText("SEND");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("CANCEL");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel4Layout = new org.jdesktop.layout.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel4Layout.createSequentialGroup()
                .add(59, 59, 59)
                .add(jButton1)
                .add(31, 31, 31)
                .add(jButton2)
                .addContainerGap(453, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel4Layout.createSequentialGroup()
                .addContainerGap(43, Short.MAX_VALUE)
                .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jButton1)
                    .add(jButton2))
                .addContainerGap())
        );

        jButton4.setText("Browse");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton6.setText("Browse");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel5.setText("ATTACHMENTS");

        org.jdesktop.layout.GroupLayout jPanel3Layout = new org.jdesktop.layout.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel5)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 30, Short.MAX_VALUE)
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                    .add(jTextField6)
                    .add(jTextField5, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 443, Short.MAX_VALUE))
                .add(18, 18, 18)
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(jButton4)
                    .add(jButton6))
                .add(28, 28, 28))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel3Layout.createSequentialGroup()
                .add(23, 23, 23)
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jButton4)
                    .add(jTextField5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 31, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jButton6)
                    .add(jTextField6, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jScrollPane1.setViewportView(jTextPane1);

        jToolBar1.setRollover(true);

        /*jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/my/MaxMailer1/open.gif"))); // NOI18N
        jButton3.setFocusable(false);
        jButton3.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton3.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton3);

        jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/my/MaxMailer1/save.gif"))); // NOI18N
        jButton5.setFocusable(false);
        jButton5.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton5.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton5);
        jToolBar1.add(jSeparator1);

        jButton7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/my/MaxMailer1/cut.gif"))); // NOI18N
        jButton7.setFocusable(false);
        jButton7.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton7.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jButton7);

        jButton8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/my/MaxMailer1/paste.gif"))); // NOI18N
        jButton8.setFocusable(false);
        jButton8.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton8.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jButton8);

        jButton9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/my/MaxMailer1/copy.gif"))); // NOI18N
        jButton9.setFocusable(false);
        jButton9.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton9.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jButton9);
        jToolBar1.add(jSeparator2);

        jButton10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/my/MaxMailer1/bold.gif"))); // NOI18N
        jButton10.setFocusable(false);
        jButton10.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton10.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jButton10);

        jButton11.setIcon(new javax.swing.ImageIcon(getClass().getResource("/my/MaxMailer1/italic.gif"))); // NOI18N
        jButton11.setFocusable(false);
        jButton11.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton11.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jButton11);

        jButton12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/my/MaxMailer1/underline.gif"))); // NOI18N
        jButton12.setFocusable(false);
        jButton12.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton12.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jButton12);
        jToolBar1.add(jSeparator3);

        jButton13.setIcon(new javax.swing.ImageIcon(getClass().getResource("/my/MaxMailer1/left.gif"))); // NOI18N
        jButton13.setFocusable(false);
        jButton13.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton13.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jButton13);

        jButton14.setIcon(new javax.swing.ImageIcon(getClass().getResource("/my/MaxMailer1/center.gif"))); // NOI18N
        jButton14.setFocusable(false);
        jButton14.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton14.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jButton14);

        jButton15.setIcon(new javax.swing.ImageIcon(getClass().getResource("/my/MaxMailer1/right.gif"))); // NOI18N
        jButton15.setFocusable(false);
        jButton15.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton15.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jButton15);
        jToolBar1.add(jSeparator4);
*/

         jToolBar1.add(getOpenAction()).setText("");
        jToolBar1.add(getSaveAction()).setText("");
        jToolBar1.addSeparator();

        // Add cut/copy/paste buttons.
        jToolBar1.add(jTextPane1.getActionMap().get(DefaultEditorKit.cutAction)).setText("");
        jToolBar1.add(jTextPane1.getActionMap().get(DefaultEditorKit.copyAction)).setText("");
        jToolBar1.add(jTextPane1.getActionMap().get(DefaultEditorKit.pasteAction)).setText("");
        jToolBar1.addSeparator();

        jToolBar1.add(jTextPane1.getActionMap().get("font-bold")).setText("");
        jToolBar1.add(jTextPane1.getActionMap().get("font-italic")).setText("");
        jToolBar1.add(jTextPane1.getActionMap().get("font-underline")).setText("");
        jToolBar1.addSeparator();

        jToolBar1.add(jTextPane1.getActionMap().get("left-justify")).setText("");
        jToolBar1.add(jTextPane1.getActionMap().get("center-justify")).setText("");
        jToolBar1.add(jTextPane1.getActionMap().get("right-justify")).setText("");
        jToolBar1.addSeparator();
        
       // jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
       // jComboBox2.setToolTipText("Text Color");
         jToolBar1.add(jComboBox2);
        
        
        GraphicsEnvironment e=GraphicsEnvironment.getLocalGraphicsEnvironment();
        String[] fontNames=e.getAvailableFontFamilyNames();
        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(fontNames));
         jToolBar1.add(jComboBox1);
         jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });
         
       //jComboBox1.setToolTipText("Font-Type");
       /* jComboBox1.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				String fontFamily= (String)jComboBox1.getSelectedItem();
			        System.out.println(fontFamily);
                                  if(!StyleConstants.getFontFamily(attributes).equals(fontFamily)) {
                                            StyleConstants.setFontFamily(attributes,fontFamily);
                                        }
                                updatefont();
                                //item.getColor() method will return the current color selected
			}
		});*/


         String fontsz[]={"8","10","12","14","16","20","24","28","36","48"};
        jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(fontsz));
        jToolBar1.add(jComboBox3);
        jComboBox3.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				String fontSize= (String)jComboBox3.getSelectedItem();
			        System.out.println(fontSize);
                                if(StyleConstants.getFontSize(attributes) !=Integer.parseInt(fontSize)) {
                                    StyleConstants.setFontSize(attributes,Integer.parseInt(fontSize));
    }                               updatefont();
        		}
		});   

        /*jMenu1.setText("File");

        jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, 0));
        jMenuItem1.setText("Open");
        jMenu1.add(jMenuItem1);

        jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, 0));
        jMenuItem2.setText("Save");
        jMenu1.add(jMenuItem2);

        jMenuItem3.setText("Exit");
        jMenu1.add(jMenuItem3);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edit");

        jMenuItem4.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, 0));
        jMenuItem4.setText("Cut");
        jMenu2.add(jMenuItem4);

        jMenuItem5.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, 0));
        jMenuItem5.setText("Copy");
        jMenu2.add(jMenuItem5);

        jMenuItem6.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_V, 0));
        jMenuItem6.setText("Paste");
        jMenu2.add(jMenuItem6);

        jMenuItem7.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, 0));
        jMenuItem7.setText("Select All");
        jMenu2.add(jMenuItem7);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);
*/
        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .addContainerGap()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                .add(jPanel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(layout.createSequentialGroup()
                                    .add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(3, 3, 3))
                                .add(org.jdesktop.layout.GroupLayout.LEADING, jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 677, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                            .add(jPanel4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                    .add(layout.createSequentialGroup()
                        .add(19, 19, 19)
                        .add(jToolBar1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 814, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18)
                .add(jToolBar1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 268, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18)
                .add(jPanel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(158, 158, 158))
        );
        
        
        Color[] fontcolor={Color.red,Color.blue,Color.green,Color.black,Color.orange,
                           Color.yellow,Color.pink,Color.gray,
                           Color.darkGray,Color.cyan,Color.white};

Font f=new Font("Bookman Old Style",Font.PLAIN,16);
Color c=new Color(0);
    jButton4.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                int state=chooser.showOpenDialog(null);
                File file=chooser.getSelectedFile();
                if(file!=null && state==JFileChooser.APPROVE_OPTION) {
                    filepath[0]=file.getPath();
                    jTextField5.setText(filepath[0]);
                }
            }
            });
            jButton6.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                int state=chooser.showOpenDialog(null);
                File file=chooser.getSelectedFile();
                if(file!=null && state==JFileChooser.APPROVE_OPTION) {
                    filepath[1]=file.getPath();
                    jTextField6.setText(filepath[1]);
                }
            }
            });

        pack();
    }// </editor-fold>

    private void jLabel1MouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
        c.setVisible(false);
        new Compose1().setVisible(true);
    }



    //private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
   // }

    private void jTextField3ActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }
private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
      java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
            actionSend();

            }
        });
        // TODO add your handling code here:
    }

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
    Cancelled= true;
      dispose();        // TODO add your handling code here:
    }

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }

    void updatefont()
{
    String name = StyleConstants.getFontFamily(attributes);
    boolean bold = StyleConstants.isBold(attributes);
    boolean ital = StyleConstants.isItalic(attributes);
    int size = StyleConstants.getFontSize(attributes);

    //Bold and italic don’t work properly in beta 4.
    Font f = new Font(name, (bold ? Font.BOLD : 0) +
                            (ital ? Font.ITALIC : 0), size);
    jTextPane1.setFont(f);
}
    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {
     jComboBox1.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				String fontFamily= (String)jComboBox1.getSelectedItem();
			        System.out.println(fontFamily);
                                  if(!StyleConstants.getFontFamily(attributes).equals(fontFamily)) {
                                            StyleConstants.setFontFamily(attributes,fontFamily);
                                        }
                                updatefont();
                                //item.getColor() method will return the current color selected
			}
		});  // TODO add your handling code here:
    }

   
    private void jComboBox2ActionPerformed(java.awt.event.ActionEvent evt) {
        jComboBox2.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				Item item = (Item)jComboBox2.getSelectedItem();
                                String h=(String)("Color."+item.toString());
			        System.out.println(h);
                                //StyleConstants.setForeground(attr,(Font)h);
                                 StyleContext sc = StyleContext.getDefaultStyleContext();
                                 AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY,StyleConstants.Foreground,item.getColor());
                                 jTextPane1.setCharacterAttributes(aset, false);
                                //item.getColor() method will return the current color selected
			}
		});
    }
    protected void makeActionsPretty() {
    Action a;
    a = jTextPane1.getActionMap().get(DefaultEditorKit.cutAction);
    a.putValue(Action.SMALL_ICON, new ImageIcon("C:\\project\\MaxMailer1\\src\\my\\MaxMailer1\\cut.gif"));
  //  a.putValue(Action.NAME, "Cut");

    a = jTextPane1.getActionMap().get(DefaultEditorKit.copyAction);
    a.putValue(Action.SMALL_ICON, new ImageIcon("C:\\project\\MaxMailer1\\src\\my\\MaxMailer1\\copy.gif"));
   // a.putValue(Action.NAME, "Copy");

    a = jTextPane1.getActionMap().get(DefaultEditorKit.pasteAction);
    a.putValue(Action.SMALL_ICON, new ImageIcon("C:\\project\\MaxMailer1\\src\\my\\MaxMailer1\\paste.gif"));
   // a.putValue(Action.NAME, "Paste");

    a = jTextPane1.getActionMap().get(DefaultEditorKit.selectAllAction);
  //  a.putValue(Action.NAME, "Select All");

    a = getTextComponent().getActionMap().get("font-bold");
    a.putValue(Action.SMALL_ICON, new ImageIcon("C:\\project\\MaxMailer1\\src\\my\\MaxMailer1\\bold.gif"));
  //  a.putValue(Action.NAME, "Bold");

    a = getTextComponent().getActionMap().get("font-italic");
    a.putValue(Action.SMALL_ICON, new ImageIcon("C:\\project\\MaxMailer1\\src\\my\\MaxMailer1\\italic.gif"));
  //  a.putValue(Action.NAME, "Italic");

    a = getTextComponent().getActionMap().get("font-underline");
    a.putValue(Action.SMALL_ICON, new ImageIcon("C:\\project\\MaxMailer1\\src\\my\\MaxMailer1\\underline.gif"));
//    a.putValue(Action.NAME, "Underline");

    a = getTextComponent().getActionMap().get("left-justify");
    a.putValue(Action.SMALL_ICON, new ImageIcon("C:\\project\\MaxMailer1\\src\\my\\MaxMailer1\\left.gif"));

    a = getTextComponent().getActionMap().get("center-justify");
    a.putValue(Action.SMALL_ICON, new ImageIcon("C:\\project\\MaxMailer1\\src\\my\\MaxMailer1\\center.gif"));

    a = getTextComponent().getActionMap().get("right-justify");
    a.putValue(Action.SMALL_ICON, new ImageIcon("C:\\project\\MaxMailer1\\src\\my\\MaxMailer1\\right.gif"));

  }
protected JMenuBar createMenuBar() {
    JMenuBar menubar = new JMenuBar();
    JMenu file = new JMenu("File");
    JMenu edit = new JMenu("Edit");
    JMenu font = new JMenu("Font");
    menubar.add(file);
    menubar.add(edit);
    //menubar.add(font);

    file.add(getOpenAction());
    file.add(getSaveAction());
    file.add(new ExitAction());
    edit.add(jTextPane1.getActionMap().get(DefaultEditorKit.cutAction)).setText("Cut");
    edit.add(jTextPane1.getActionMap().get(DefaultEditorKit.copyAction)).setText("Copy");
    edit.add(jTextPane1.getActionMap().get(DefaultEditorKit.pasteAction)).setText("Paste");
    edit.add(jTextPane1.getActionMap().get(DefaultEditorKit.selectAllAction));
    /*JMenu style = new JMenu("Style");
    style.add(jTextPane1.getActionMap().get("font-bold")).setText("Bold");
    style.add(jTextPane1.getActionMap().get("font-italic")).setText("Italic");
    style.add(jTextPane1.getActionMap().get("font-underline")).setText("Underline");
     JMenu Font = new JMenu("Font-family");


    JMenu size = new JMenu("Size");

    JMenu fontFamily=new JMenu("Font-Family");
    Font.add(jTextPane1.getActionMap().get("font-agency FB")).setText("");
    Font.add(jTextPane1.getActionMap().get("font-comic sans MS")).setText("");
    Font.add(jTextPane1.getActionMap().get("font-Times new roman")).setText("");

    JMenu colmenu = new JMenu("Color");
    font.add(fontFamily);
    font.add(size);
    font.add(style);
    font.add(colmenu);
     * 
     */


    return menubar;
  }
     protected Action getOpenAction() { return openAction; }

  // Subclass can override to use a different save action.
  protected Action getSaveAction() { return saveAction; }

  protected JTextComponent getTextComponent() { return jTextPane1; }
  // A very simple exit action
  public class ExitAction extends AbstractAction {
    public ExitAction() { super("Exit"); }
    public void actionPerformed(ActionEvent ev) { System.exit(0); }
  }

  // An action that opens an existing file
  class OpenAction extends AbstractAction {
    public OpenAction() {
      super("Open", new ImageIcon("C:\\project\\MaxMailer1\\src\\my\\MaxMailer1\\Open.gif"));
    }

    // Query user for a filename and attempt to open and read the file into the
    // text component.
    public void actionPerformed(ActionEvent ev) {
      JFileChooser chooser = new JFileChooser();
      if (chooser.showOpenDialog(ComposeFinal.this) !=
          JFileChooser.APPROVE_OPTION)
        return;
      File file = chooser.getSelectedFile();
      if (file == null)
        return;

      FileReader reader = null;
      try {
        reader = new FileReader(file);
        jTextPane1.read(reader, null);
      }
      catch (IOException ex) {
        JOptionPane.showMessageDialog(ComposeFinal.this,
        "File Not Found", "ERROR", JOptionPane.ERROR_MESSAGE);
      }
      finally {
        if (reader != null) {
          try {
            reader.close();
          } catch (IOException x) {}
        }
      }
    }
  }

  // An action that saves the document to a file
  class SaveAction extends AbstractAction {
    public SaveAction() {
      super("Save", new ImageIcon("C:\\project\\MaxMailer1\\src\\my\\MaxMailer1\\save.gif"));
    }

    // Query user for a filename and attempt to open and write the text
    // component’s content to the file.
    public void actionPerformed(ActionEvent ev) {
      JFileChooser chooser = new JFileChooser();
      if (chooser.showSaveDialog(ComposeFinal.this) !=
          JFileChooser.APPROVE_OPTION)
        return;
      File file = chooser.getSelectedFile();
      if (file == null)
        return;

      FileWriter writer = null;
      try {
        writer = new FileWriter(file);
        jTextPane1.write(writer);
      }
      catch (IOException ex) {
        JOptionPane.showMessageDialog(ComposeFinal.this,
        "File Not Saved", "ERROR", JOptionPane.ERROR_MESSAGE);
      }
      finally {
        if (writer != null) {
          try {
            writer.close();
          } catch (IOException x) {}
        }
      }
    }
  }

    /**
     * @param args the command line arguments
     */
    public static void main(String []args) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                String host="Smtp.bol.net.in";
                String user="[email protected]";
                String password="2091464293";
                new ComposeFinal(host,user, password).setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton10;
    private javax.swing.JButton jButton11;
    private javax.swing.JButton jButton12;
    private javax.swing.JButton jButton13;
    private javax.swing.JButton jButton14;
    private javax.swing.JButton jButton15;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JComboBox jComboBox3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JMenuItem jMenuItem6;
    private javax.swing.JMenuItem jMenuItem7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JToolBar.Separator jSeparator1;
    private javax.swing.JToolBar.Separator jSeparator2;
    private javax.swing.JToolBar.Separator jSeparator3;
    private javax.swing.JToolBar.Separator jSeparator4;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField6;
   //private javax.swing.JTextPane jTextPane1;
    private javax.swing.JToolBar jToolBar1;
    // End of variables declaration
    private javax.swing.JFileChooser chooser=new JFileChooser();
    private static ComposeFinal c;

    private boolean Cancelled;
}


class Item {
	private Color color;
	private String string;

	public Item(Object[] array) {
		color = (Color)array[0];
		string = (String)array[1];
	}
	public Color getColor() { return color; }
	public String toString() { return string; }
}

class ColorRenderer extends JLabel implements ListCellRenderer {
	private static ColorIcon icon = new ColorIcon();

	private Border
		redBorder = BorderFactory.createLineBorder(Color.red,2),
		emptyBorder = BorderFactory.createEmptyBorder(2,2,2,2);

	public Component getListCellRendererComponent(
									JList list,
									Object value,
									int index,
									boolean isSelected,
									boolean cellHasFocus) {
		Item item = (Item)value;
		icon.setColor(item.getColor());
		setIcon(icon);
		setText(item.toString());
		if(isSelected) setBorder(redBorder);
		else 		   setBorder(emptyBorder);

		return this;
	}
}
class ColorIcon implements Icon {
	private Color color;
	private int w, h;

	public ColorIcon() {
		this(Color.gray, 50, 15);
	}
	public ColorIcon(Color color, int w, int h) {
		this.color = color;
		this.w = w;
		this.h = h;
	}
	public void paintIcon(Component c, Graphics g, int x, int y) {
		g.setColor(Color.black);
		g.drawRect(x, y, w-1, h-1);
		g.setColor(color);
		g.fillRect(x+1, y+1, w-2, h-2);
	}
	public Color getColor() {
		return color;
	}
	public void setColor(Color color) {
		this.color = color;
	}
	public int getIconWidth() {
		return w;
	}
	public int getIconHeight() {
		return h;
	}
}





Is This A Good Question/Topic? 0
  • +

Replies To: getText() returns null when refered with jTextPane

#2 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon

Reputation: 2965
  • View blog
  • Posts: 11,222
  • Joined: 15-July 08

Re: getText() returns null when refered with jTextPane

Posted 26 April 2010 - 07:48 AM

According to the docs: http://java.sun.com/....html#getText() this returns null when there is no text in the text field. You may want to put a check on it.

if (textField.getText() == null)
    // Then don't do it. Return from method.


Was This Post Helpful? 0
  • +
  • -

#3 immeraufdemhund  Icon User is offline

  • D.I.C Regular

Reputation: 79
  • View blog
  • Posts: 495
  • Joined: 29-March 10

Re: getText() returns null when refered with jTextPane

Posted 26 April 2010 - 08:00 AM

although your code is hard to read from what i can figure you didn't allow the program to put any text into your JTextPane before it called the getText() function. I did a small test in one of my programs and i made it enter text 2 ways and than i hit a button and it read the text perfectly each time. but it was in order: new JTextPane, jpane.setText (or enter text manually), jpane.getText. and it worked everytime.

although i can tell you wrote this program using netbeans i copied your full program into my netbeans and it can't find the javax.mail...nor is it in sun java's over view of classes.... soooo were did you get it? :) ... I noticed that the programs initializes all new componants than you use the getText..well you never got the chance to get the actual message yet. that's why your getting null values. And you don't need to instantiate a new one it's in your code like 5 times.. just a thought.
Was This Post Helpful? 0
  • +
  • -

#4 japanir  Icon User is offline

  • jaVanir
  • member icon

Reputation: 1014
  • View blog
  • Posts: 3,025
  • Joined: 20-August 09

Re: getText() returns null when refered with jTextPane

Posted 26 April 2010 - 11:08 AM

@immeraufdemhund
javax.mail is part of the JavaMail API.
if you not familiar with the JavaMail API, here is a useful link:
http://java.sun.com/...docs/index.html
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1