How to get format from textpane?

iam changing the color and inserting image in jtextpane after i have to send a mail.
how to get that formatted data and send to mail plz help in this case.
change the code and send it. plz...............
import java.awt.*;
import javax.swing.*;
import javax.swing.JTabbedPane.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.event.*;
import javax.swing.text.*;
import javax.swing.text.rtf.*;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class loginform extends JFrame {
     JTabbedPane jtp = new JTabbedPane();
     public loginform() {
          Container c = getContentPane();
          JTabbedPane jtp = new JTabbedPane();
          jtp.addTab("COMPOSEMAIL", new ComposeMailPanel());
          c.add(jtp);
          c.validate();
     }//method
     public static void main(String a[]) throws Exception {
          loginform s = new loginform();
          s.setSize(800, 800);
          s.setVisible(true);
     }//main
}//mainclass
class ComposeMailPanel extends JPanel implements ActionListener {
     JTextField BCC;
     int start;
     int end;
     JLabel JLabel1;
     JLabel JLabel2;
     JLabel JLabel3;
     JLabel JLabel4;
     JFrame mainFrame = new JFrame();
     JTextField from;
     JTextField subject;
     JButton Send;
     String mailsentaddress = "";
     JButton bInsertPic = new JButton("P");
     JButton bForegroundColor = new JButton("F");
     JFileChooser insertIconFile = new JFileChooser();
     JColorChooser backgroundChooser = new JColorChooser();
     JColorChooser foregroundChooser = new JColorChooser();
     Color foregroundColor;
     JTextPane mainTextPane = new JTextPane();
     SimpleAttributeSet sas = new SimpleAttributeSet();
     MutableAttributeSet sas1 = new SimpleAttributeSet();
     StyleContext sc = new StyleContext();
     MutableAttributeSet mas;
     DefaultStyledDocument dse = new DefaultStyledDocument(sc);
     JScrollPane mainScrollPane = new JScrollPane(mainTextPane, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
     RTFEditorKit rtfkit = new RTFEditorKit();
     Dimension Size1 = new Dimension();
     public ComposeMailPanel() {
          setLayout(null);
          mainTextPane.setBounds(150, 325, 572, 150);
          mainTextPane.setContentType("text/html");
          mainTextPane.setEditorKit(rtfkit);
          mainTextPane.setDocument(dse);
          mainScrollPane.setBounds(150, 325, 572, 155);
          bInsertPic.setBounds(150, 300, 20, 20);
          bForegroundColor.setBounds(171, 300, 20, 20);
          add(mainScrollPane);
          add(bInsertPic);
          add(bForegroundColor);
          mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          bInsertPic.addActionListener(this);
          bInsertPic.setToolTipText("Insert picture");
          bForegroundColor.addActionListener(this);
          bForegroundColor.setToolTipText("Text color");
          JLabel1 = new JLabel("FROM  :");
          add(JLabel1);
          JLabel1.setBounds(30, 205, 110, 20);
          JLabel2 = new JLabel("BCC :");
          add(JLabel2);
          JLabel2.setBounds(30, 235, 110, 20);
          JLabel3 = new JLabel("SUBJECT :");
          add(JLabel3);
          JLabel3.setBounds(30, 265, 110, 20);
          JLabel4 = new JLabel("MESSAGE :");
          add(JLabel4);
          JLabel4.setBounds(30, 325, 110, 20);
          from = new JTextField();
          add(from);
          from.setBounds(150, 210, 577, 20);
          BCC = new JTextField();
          add(BCC);
          BCC.setBounds(150, 240, 577, 20);
          subject = new JTextField();
          add(subject);
          subject.setBounds(150, 270, 577, 20);
          Send = new JButton("Send");
          add(Send);
          Send.setBounds(720, 495, 65, 20);
          Send.addActionListener(this);
     }// constructor
     public void setAttributeSet(AttributeSet attr) {
          int xStart, xFinish, k;
          xStart = mainTextPane.getSelectionStart();
          xFinish = mainTextPane.getSelectionEnd();
          k = xFinish - xStart;
          if (xStart != xFinish) {
               dse.setCharacterAttributes(xStart, k, attr, true);
          } else if (xStart == xFinish) {
               mas = rtfkit.getInputAttributes();
               mas.addAttributes(attr);
          // The below command line sets the focus to the JTextPane
          mainTextPane.grabFocus();
     public void actionPerformed(ActionEvent ae1) {
          JComponent b = (JComponent) ae1.getSource();
          String str3 = null;
          if (b == bInsertPic) {
               insertIconFile.setDialogType(JFileChooser.OPEN_DIALOG);
               insertIconFile.setDialogTitle("Select a picture to insert into document");
               if (insertIconFile.showDialog(mainFrame, "Insert") != JFileChooser.APPROVE_OPTION) {
                    return;
               File g = insertIconFile.getSelectedFile();
               ImageIcon image1 = new ImageIcon(g.toString());
               mainTextPane.insertIcon(image1);
               mainTextPane.grabFocus();
          } else if (b == bForegroundColor) {
               foregroundColor = foregroundChooser.showDialog(mainFrame,"Color Chooser", Color.white);
               if (foregroundColor != null) {
                    String s1 = mainTextPane.getSelectedText();
                    StyleConstants.setForeground(sas, foregroundColor);
                    setAttributeSet(sas);
          } else if (ae1.getSource() == Send) {
               String From = "";
               String To = "";
               String Subject = "";
               String Body = "";
               String Attachment = "";
               String Hostname = "";
               From = from.getText();
               To = BCC.getText();
               Subject = subject.getText();
               try {
                    int ki = mainTextPane.getDocument().getLength();
                    Body = mainTextPane.getStyledDocument().getText(0, ki);
                    Hostname = "192.9.200.2";
                    SmtpAttachmentExample example1 = new SmtpAttachmentExample();
                    example1.sendMessage1(Hostname, To, From, Subject, Body);
                    mailsentaddress = BCC.getText();
               } catch (Exception we1) {
class SmtpAttachmentExample {
     public void sendMessage1(String hostname, String to, String from,
               String subject, String body) {
          try {
               Properties props = System.getProperties();
               props.put("mail.smtp.host", hostname);
               Session mailsession = Session.getDefaultInstance(props, null);
               Message message = new MimeMessage(mailsession);
               message.setFrom(new InternetAddress(from));
               message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to, false));
               message.setSubject(subject);
               message.setSentDate(new Date());
               MimeBodyPart messageBodyPart = new MimeBodyPart();
               messageBodyPart.setText(body);
               Multipart multipart = new MimeMultipart();
               multipart.addBodyPart(messageBodyPart);
               message.setContent(multipart);
               Transport.send(message);
          } catch (Exception ert) {
     }//withoutattachement
}thanks in advance
raja

here it is...simple is'nt it???
package jwsdp.test;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.util.Properties;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JColorChooser;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.ScrollPaneConstants;
import javax.swing.text.AttributeSet;
import javax.swing.text.DefaultStyledDocument;
import javax.swing.text.MutableAttributeSet;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyleContext;
import javax.swing.text.rtf.RTFEditorKit;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class loginform extends JFrame {
     JTabbedPane jtp = new JTabbedPane();
     public loginform() {
          Container c = getContentPane();
          JTabbedPane jtp = new JTabbedPane();
          jtp.addTab("COMPOSEMAIL", new ComposeMailPanel());
          c.add(jtp);
          c.validate();
     }//method
     public static void main(String a[]) throws Exception {
          loginform s = new loginform();
          s.setSize(800, 800);
          s.setVisible(true);
     }//main
}//mainclass
class ComposeMailPanel extends JPanel implements ActionListener {
     JTextField BCC;
     int start;
     int end;
     JLabel JLabel1;
     JLabel JLabel2;
     JLabel JLabel3;
     JLabel JLabel4;
     JFrame mainFrame = new JFrame();
     JTextField from;
     JTextField subject;
     JButton Send;
     String mailsentaddress = "";
     JButton bInsertPic = new JButton("P");
     JButton bForegroundColor = new JButton("F");
     JFileChooser insertIconFile = new JFileChooser();
     JColorChooser backgroundChooser = new JColorChooser();
     JColorChooser foregroundChooser = new JColorChooser();
     Color foregroundColor;
     JTextPane mainTextPane = new JTextPane();
     SimpleAttributeSet sas = new SimpleAttributeSet();
     MutableAttributeSet sas1 = new SimpleAttributeSet();
     StyleContext sc = new StyleContext();
     MutableAttributeSet mas;
     DefaultStyledDocument dse = new DefaultStyledDocument(sc);
     JScrollPane mainScrollPane = new JScrollPane(mainTextPane, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
     RTFEditorKit rtfkit = new RTFEditorKit();
     Dimension Size1 = new Dimension();
     public ComposeMailPanel() {
          setLayout(null);
          mainTextPane.setBounds(150, 325, 572, 150);
          mainTextPane.setContentType("text/html");
          mainTextPane.setEditorKit(rtfkit);
          mainTextPane.setDocument(dse);
          mainScrollPane.setBounds(150, 325, 572, 155);
          bInsertPic.setBounds(150, 300, 20, 20);
          bForegroundColor.setBounds(171, 300, 20, 20);
          add(mainScrollPane);
          add(bInsertPic);
          add(bForegroundColor);
          mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          bInsertPic.addActionListener(this);
          bInsertPic.setToolTipText("Insert picture");
          bForegroundColor.addActionListener(this);
          bForegroundColor.setToolTipText("Text color");
          JLabel1 = new JLabel("FROM  :");
          add(JLabel1);
          JLabel1.setBounds(30, 205, 110, 20);
          JLabel2 = new JLabel("BCC :");
          add(JLabel2);
          JLabel2.setBounds(30, 235, 110, 20);
          JLabel3 = new JLabel("SUBJECT :");
          add(JLabel3);
          JLabel3.setBounds(30, 265, 110, 20);
          JLabel4 = new JLabel("MESSAGE :");
          add(JLabel4);
          JLabel4.setBounds(30, 325, 110, 20);
          from = new JTextField();
          add(from);
          from.setBounds(150, 210, 577, 20);
          BCC = new JTextField();
          add(BCC);
          BCC.setBounds(150, 240, 577, 20);
          subject = new JTextField();
          add(subject);
          subject.setBounds(150, 270, 577, 20);
          Send = new JButton("Send");
          add(Send);
          Send.setBounds(720, 495, 65, 20);
          Send.addActionListener(this);
     }// constructor
     public void setAttributeSet(AttributeSet attr) {
          int xStart, xFinish, k;
          xStart = mainTextPane.getSelectionStart();
          xFinish = mainTextPane.getSelectionEnd();
          k = xFinish - xStart;
          if (xStart != xFinish) {
               dse.setCharacterAttributes(xStart, k, attr, true);
          } else if (xStart == xFinish) {
               mas = rtfkit.getInputAttributes();
               mas.addAttributes(attr);
          // The below command line sets the focus to the JTextPane
          mainTextPane.grabFocus();
     public void actionPerformed(ActionEvent ae1) {
          JComponent b = (JComponent) ae1.getSource();
          String str3 = null;
          if (b == bInsertPic) {
               insertIconFile.setDialogType(JFileChooser.OPEN_DIALOG);
               insertIconFile.setDialogTitle("Select a picture to insert into document");
               if (insertIconFile.showDialog(mainFrame, "Insert") != JFileChooser.APPROVE_OPTION) {
                    return;
               File g = insertIconFile.getSelectedFile();
               ImageIcon image1 = new ImageIcon(g.toString());
               mainTextPane.insertIcon(image1);
               mainTextPane.grabFocus();
          } else if (b == bForegroundColor) {
               foregroundColor = foregroundChooser.showDialog(mainFrame,"Color Chooser", Color.white);
               if (foregroundColor != null) {
                    String s1 = mainTextPane.getSelectedText();
                    StyleConstants.setForeground(sas, foregroundColor);
                    setAttributeSet(sas);
          } else if (ae1.getSource() == Send) {
               String From = "";
               String To = "";
               String Subject = "";
               String Body = "";
               String Attachment = "";
               String Hostname = "";
               From = from.getText();
               To = BCC.getText();
               Subject = subject.getText();
               try {
                    int ki = mainTextPane.getDocument().getLength();
                    ByteArrayOutputStream l_out = new ByteArrayOutputStream();                  // added by Guilllaume
                    mainTextPane.getEditorKit().write(l_out,mainTextPane.getDocument(),0,ki);   // added by Guilllaume
                    Body = new String(l_out.toByteArray());                                     // added by Guilllaume
                //     Body = mainTextPane.getStyledDocument().getText(0, ki); // supress by Guilllaume
                    Hostname = "192.9.200.2";
                    SmtpAttachmentExample example1 = new SmtpAttachmentExample();
                    example1.sendMessage1(Hostname, To, From, Subject, Body);
                    mailsentaddress = BCC.getText();
               } catch (Exception we1) {
class SmtpAttachmentExample {
     public void sendMessage1(String hostname, String to, String from,
               String subject, String body) {
          try {
               Properties props = System.getProperties();
               props.put("mail.smtp.host", hostname);
               Session mailsession = Session.getDefaultInstance(props, null);
               Message message = new MimeMessage(mailsession);
               message.setFrom(new InternetAddress(from));
               message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to, false));
               message.setSubject(subject);
               message.setSentDate(new Date());
               MimeBodyPart messageBodyPart = new MimeBodyPart();
               messageBodyPart.setText(body);
               Multipart multipart = new MimeMultipart();
               multipart.addBodyPart(messageBodyPart);
               message.setContent(multipart);
               Transport.send(message);
          } catch (Exception ert) {
     }//withoutattachement
}

Similar Messages

  • How can get formatted data from hard drive

    how can get formatted data from hard drive?

    No chance without special tools/knowledge. There are companies that can do it, unless you use multiple format or rewrite data with special erase ustility or unless you have done low level format.
    Regards
    Milos

  • How to get photos from iphoto back onto an SD card. I have a MacBook Pro with a built in SC card slot.

    How to get photos from iPhoto back onto a SD card. I have a MacBook Pro with built in SD card slot. I have tried "Export" but this does not work.

    It's best to export the photos to a folder and then drag the folder onto the memory card.  Memory cards are usually formatted for PCs, FAT 32, which doesn't permit more than a limited number of files in the root directory. Putting the photos in a folder gets around that limitation.
    OT

  • How to get answers from forum

    Hi,
    Just wondering, how to get answer from forum.  Some time, for simple question, I don't see anybody replying. 
    Is there any other platform we get define answer or is there any support who can connect to our system suggest resolution?
    Thanks,
    -Anand

    anand_gp wrote:
    Just wondering, how to get answer from forum.  Some time, for simple question, I don't see anybody replying.
    If it's really a simple question, then most people probably think the poster can get the answer from the documentation, or by searching the forum for previous answers.
    However, most of the time, it's not that the question actually is simple. It's usually a question that is being asked simplistically, making it nearly impossible to answer (or often even understand). To get an effective response to a question, it needs to be the right question, asked in the right way.
    Describe the the problem/requirement (not the attempted solutions) in detail:
    How to ask questions
    Re: 2. How do I ask a question on the forums?
    Include as much relevant information with the question as possible, starting with:
    APEX version
    DB version, edition and host OS
    Web server architecture (EPG, OHS or APEX listener), server platform, and host OS
    Browser(s)/version(s) used
    UI/Theme
    Templates
    Region type (making particular distinction as to whether a "report" is a standard report, an interactive report, or in fact an "updateable report" (i.e. a tabular form)
    With APEX we're also fortunate to have a great resource in apex.oracle.com where we can reproduce and share problems. Reproducing things there is the best way to troubleshoot most issues, especially those relating to layout and visual formatting. To get a detailed answer then it's appropriate for the questioner to take on a significant part of the effort by reproducing the problem on apex.oracle.com before asking for assistance with specific issues, which can then be seen at first hand in a real APEX environment.

  • How to get music from someone else's itunes library onto your

    How to get music from someone else's itunes library onto your

    I have a different problem, perhaps someone can help.
    My friends music library is on a hard drive, I can move songs to my library, they play fine on my computer.....However, when I try to move them to my i-phone, they turn to a light grey color and will not play on my phone.  They also have a circle with dots in front of the song.
    Some security limitation apparently, just trying to over-ride.
    Song format is .m4a

  • How to get photos from mac to iPhone 6? when i try it just comes up iCloud instead of my photos

    how to get photos from mac to iPhone 6? when i try it just comes up iCloud instead of my photos

    Make sure Settings > iCloud > Photos > iCloud Photo Library (Beta) = "Off"
    Then sync your iPhone using iTunes and make sure your sync settings for photos are set correctly in iTunes.

  • I got a new computer and don't know how to get music from ipod touch to itunes library

    I recently got a new computer and don't know how to get music from my ipod touch to show on my itunes library. 

    You need to transfer the iTunes folder from the old computer to the new one.
    iTunes: How to move your music to a new computer (Mac or Windows):
      http://support.apple.com/kb/HT4527

  • I have a new MacAir and don't know how to get info from my USB stick and my SD photo card.  Can anyone help me please?

    I have a new MacBook Air and don't know how to get info from my USB stick and get info from my SD card.  Can anyone help, please?

    Plug the stick and/or card into the appropriate slots on the side of your Air. Do you see icons for the devices appear on the desktop? Click into them to see what files are there.
    Matt

  • How to get data from a USB-UIRT device using Labview?

    How to get data from a USB-UIRT device using Labview?
    I'm trying to get data from a USB-UIRT device, is it posible with Labview?
    I really appreciate your help, 
    thanks

    You may want to contact the developer of the device for the API and DLL.
    http://65.36.202.170/phpBB2/viewforum.php?f=3

  • How to get file from server while click on link

    Hi,
    i created on link and i gave one server path to select file from server but while clickinng on link it no displaying any thing.
    following is the Destination url that i gave for the item.
    /u08/app/appvis/xxex/inst/xxex_apps/xxrbe/logs/appl/conc/log/
    please tell me how to get file from server while click on link.

    Ok I got your requirement now.
    If you are getting file names from view attribute then you should not be adding destination URI property for the link.
    Instead you can use OADataBoundValueViewObject API.
    Try below code in your controller processRequest method:
    I am assuming that you are using classic table.
    Also in below example it considers OAMessageStyleText and you can replace it with link item if you want.
    OATableBean tableBean =
    (OATableBean)webBean.findChildRecursive("<table item id>");
    OAMessageStyledTextBean m= (OAMessageStyledTextBean)tableBean.findChildRecursive("<message styled text in table item id>");
    OADataBoundValueViewObject tip1 = new OADataBoundValueViewObject(m, "/u08/app/appvis/xxex/inst/xxex_apps/xxrbe/logs/appl/conc/log/"+"<vo attr name which stores file name for each row>");
    m.setAttributeValue(oracle.cabo.ui.UIConstants.DESTINATION_ATTR, tip1);
    Regards,
    Sandeep M.

  • How to get value from list item

    Hi all,
    How to get value from list item?
    I have a problem with the List Item object
    in the Oracle forms.
    How can I retrieve the selected item from
    a list ?
    I didn't find any function like 'list.GET_
    SELECTED_ITEM()'...
    thanks
    Bala

    Hello,
    You get the value as for any other Forms item:
    :value := :block.list_tem ;Francois

  • How to get FILENAME from FILE PATH

    does anyone know how to get filename from a file path for example
    FILE PATH: C:\Project\uploadbean\web\uploads\Button.txt
    returns
    FILENAME: Button.txt

    @BalusC
    ust for a reference cause i'm new in JSP This has nothing to do with JSP, but with basic knowledge of an essential API. I have given you the link to the File API. Are you saying that you refused to read the API documentation, which clearly explains you how to use the File and shows which methods are all available to you undereach the straightforward getName() method, and expecting that the others may chew the answers for you? Loser.

  • How to get data from PDF form?

    PDF forms can send data in url like GET or POST method. Is it possible to get data from url, like in PHP http://sever/file.php?item1=value1&item2=value2&item3=value3
    In APEX url have specific construction and I don't know how to get value of items (1...3)
    Please let me help to find simple method of geting data from URL.
    Best Regards,
    Mark

    The APEX URL syntax is detailed here
    http://download.oracle.com/docs/cd/E14373_01/appdev.32/e11838/concept.htm#BCEDJBEH
    How to get it from PDF is another matter...
    I'm working on an app that downloads PDFs with a Large amount of data as a blob, takes that blob and changes it to XML, then goes through the xml to validate each section of data and then add it into the schema that my apex app is referencing....
    I didn't write the original code but I do know that it isn't a quick thing to implement and includes using some uploading some java jar files to your schema and writing some custom java code.
    Someone else may be able to help with grabbing PDF data into the URL for the amounts of data you want to pass to apex.
    Gus..
    REWARDS: Please remember to mark helpful or correct posts on the forum, not just for my answers but for everyone!
    Edited by: Gussay on Sep 21, 2009 5:52 PM

  • How to get Position from EmployeeInfo in DIAPI

    I am using DIAPI(JCO) for SAP B1. According to one or my reuirement i am in need of Position from the EmployeesInfo. But there  seems no option or method for getting position from that. Can anyone guide me how to get that from EmployeesInfo ? Any help is appreciated..

    Looking at the DI API properties vs. DB fields mapping documentation in the SAP Business One developer area (https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/c5f5dbcc-0a01-0010-5d82-f25f2bee715e)
    it seems that this field is not exposed (yet).
    I.e. you could only run a SQL statement to get this information.
    Sorry,
    Frank

  • How to get songs from computer to iphone

    how to get songs from computer (I tunes) to iphone?

    Have you read the User Guide? http://support.apple.com/manuals/#iphone
    Syncing iPad, iPhone, or iPod touch with iTunes
    Syncing music to iPod or iPhone

Maybe you are looking for

  • Windows 8.1 hibernation still not working for me properly

    I see that this was already discussed in the past; but for me hibernation on Windows 8.1 still does not always work properly. Link to previous question: http://social.technet.microsoft.com/Forums/windows/en-US/238ec268-a2dc-49ab-8a75-c185710e086a/win

  • Can't get sound to play using audio line in

    I am trying to play audio from my iPhone by connecting mini plug cable to the headphone jack and the audio line-in mini plug.  The input level indicator in System Preferences > Sound is showing that audio is playing but I don't hear sound.  I do have

  • Update statement in After report trigger

    Hi I've written an update statement on a standard table to update one of its attributes in after report trigger. And then commit. I tried running the report without moving to reports top. The table was not updated. What could have gone wrong? Thanks

  • Reg:tax codes

    hi my client is having 5 different locations and for that 5 locations i have created different tax codes but the users should view only the tax codes that are applicable for their location only  how to do this???

  • Where can I get the acrobat plugins samples?

    I have acrobat sdk 9 and some samples inside folder pluginsupport/samples However, when I read live.doc (http://support.adobe.com/devsup/devsup.nsf/docs/51634.htm), there are some other sample of SDK: UIBasic, AddImage, ...  (I need to operate with i