JTable header problem plz help me

hi
i want to insert JTable in JTextPane but I have two problems
i can't do this so any help plz
1- i want to insert table with header and allow the user to edit (write) on the table header when running the
program
2- i want to insert table without header but i want to make the table column still resizable

hi
i want to insert JTable in JTextPane but I have two problems
i can't do this so any help plz
1- i want to insert table with header and allow the user to edit (write) on the table header when running the
program
2- i want to insert table without header but i want to make the table column still resizable

Similar Messages

  • JTable listener problem,  plz. help  code included

    hi,
    I need help in this JTable. If you run the following code you'll see when you double click in any cell scrollbars will appear if the text is too large for the JTextArea. What I want is when any cell is selected and if the text is too large to fit in the JTextArea I want the scrollbars to appear then. And if I double click in any cell I want some other action to take place. Here is the example code that I got from net and I am trying to play arround with this code. Please run the following code and see what I mean:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    import java.util.*;
    import javax.swing.table.*;
    import javax.swing.border.*;
    public class MyMultiRowTableTest extends JFrame
    public MyMultiRowTableTest()
    addWindowListener(new WindowAdapter()
    public void windowClosing(WindowEvent we)
    System.exit(0);
    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(initComponents(), BorderLayout.CENTER);
    protected Container initComponents()
    JPanel mainPanel = new JPanel(new BorderLayout());
    Vector vRows = new Vector();
    Vector vColumns = new Vector();
    vColumns.add("Column1");
    vColumns.add("Column2");
    for (int i=0; i<20; i++)
    Vector vRow = new Vector(2);
    vRow.add(""+(i+1)+". abcdefghijklmnopqrstuvwxyzabcdefghijk" +
    "lmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmno" +
    "pqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstu" +
    "wxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef" +
    "ghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrs"+
    "tuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghi" +
    "jklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"+
    "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrs"+
    "tuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
    vRow.add("asldfjasldfjal�dfjal�jdfal");
    vRows.add(vRow);
    JTable myTable = new JTable(vRows, vColumns);
    for (int i=0; i<myTable.getColumnCount(); i++)
    TableColumn tc = myTable.getColumn(myTable.getColumnName(i));
    if (tc!=null)
    tc.setCellRenderer(new MultiLineCellRenderer());
    tc.setCellEditor(new MultiLineCellEditor());
    myTable.setRowHeight(80);
    mainPanel.add(new JScrollPane(myTable));
    return mainPanel;
    public static void main(String[] args)
    JFrame frame = new MyMultiRowTableTest();
    frame.setSize(800,600);
    frame.setLocation(200,200);
    frame.setVisible(true);
    }//end of the class MyMultiRowTableTest
    class MultiLineCellEditor extends DefaultCellEditor
    protected JTextArea myEditingComponent;
    public MultiLineCellEditor()
    super(new JTextField());
    myEditingComponent = new JTextArea();
    myEditingComponent.setLineWrap(true);
    myEditingComponent.setWrapStyleWord(true);
    myEditingComponent.setOpaque(true);
    myEditingComponent.addKeyListener(new KeyAdapter()
    public void keyPressed(KeyEvent ke)
    if ((ke.getKeyCode()==ke.VK_ENTER) && (ke.getModifiers() == ke.CTRL_MASK))
    stopCellEditing();
    public Object getCellEditorValue()
    return myEditingComponent.getText();
    public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected,
    int row, int column)
    Component result = super.getTableCellEditorComponent(table,
    value, isSelected, row, column);
    myEditingComponent.setFont(table.getFont());
    myEditingComponent.setText(""+value);
    if (value instanceof String)
    result = new JScrollPane(myEditingComponent);
    return result ;
    }//end of the class MultiLineCellEditor
    class MultiLineCellRenderer extends JTextArea implements TableCellRenderer
    protected final static Border emptyBorder = BorderFactory.createEmptyBorder(1,2,1,2);
    protected final static Border focusBorder = UIManager.getBorder("Table.focusCellHighlightBorder");
    public MultiLineCellRenderer()
    setLineWrap(true);
    setWrapStyleWord(true);
    setOpaque(true);
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
    boolean hasFocus, int row, int column)
    if (isSelected)
    setForeground(table.getSelectionForeground());
    setBackground(table.getSelectionBackground());
    else
    setForeground(table.getForeground());
    setBackground(table.getBackground());
    setFont(table.getFont());
    if (hasFocus)
    setBorder(focusBorder);
    if (table.isCellEditable(row, column))
    setForeground( UIManager.getColor("Table.focusCellForeground") );
    setBackground( UIManager.getColor("Table.focusCellBackground") );
    else
    setBorder(emptyBorder);
    if(value==null)
    myEditingComponent.setText("");
    return new JScrollPane
    (myEditingComponent);
    setText((value == null) ? "" : value.toString());
    return this;
    }//end of the class MultiLineCellRenderer
    If you see when you double click in the first column the scrollbars will appear as the text is too large. But what I need is that when the cell is selected the scrollbars should appear and when I doubleclick in the cell I want some other action to take place. Please help I really don't understand how this cellrenderer and celleditor works. Any help is really appreciated. And thank you in advance.

    hi friend
    i tried to solve your problem , but i couldn't clear myself with program logic u used. but your problem can be solved by trying with the following lines.you need to explore the right place in your logic.
    int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS;
    int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS;
    if (value instanceof String)
    result = new JScrollPane(myEditingComponent,v,h);
    return result ;
    in the meanwhile i will try with your code as soon i will get time.
    reply me back if it solves the problem
    bye

  • Audio Clip problem plz help..

    There is some problem with my code. It is actually for simply playing a wav file.
    It gives errors on two lines....
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import javax.swing.*;
    public class MediaPlayerDemo extends JFrame
         AudioClip clip; //Error Here
         public MediaPlayerDemo(String title)
              super(title);
         clip = getAudioClip(getCodeBase(),"access.wav"); //Error Here
         clip.loop();
         public static void main(String args[])
              MediaPlayerDemo m = new MediaPlayerDemo("Title");
              m.setSize(400,400);
              m.setVisible(true);
    }

    "Audio Clip problem plz help"
    You have to learn to help yourself.
    Have you done anything to try to fix the errors yourself?
    AudioClip clip; //Error Here
    the error generated here is self-explanatory.
    if you can't fix this, you should get a good book on java basics and start again.
    the other error is also easy to fix.

  • Classpath problem plz help me

    hi!
    i am unable to run my RMI server program .Name of My server class is SumServer.java,it implements SumInterface.java all the files(.class,.java and stub) are at location c:\javaprog\rmi\sum.
    I have not put them in any package.
    value of classpath is
    classpath=c:\jdk1.4\lib;.;c:\javaprog\rmi\sum
    i go in sum folder and run the program
    c:\javaprog\rmi\sum > SumServer
    it gives me following exception.plz help me out.
    Thx in advance.
    Exception occur.Unable to register serverjava.rmi.ServerException: RemoteExcepti
    on occurred in server thread; nested exception is:
    java.rmi.UnmarshalException: error unmarshalling arguments; nested excep
    tion is:
    java.lang.ClassNotFoundException: SumServer_Stub

    Deepa lakshmi wrote:
    Hi,
    Am new to weblogic.
    Am using the tools are,
    Weblogic8.1 version
    MySql5.0,mysql-connector-java-3.1.12-bin.jar file
    While test configuration of connection pooling am getting the error is "JDBC Driver is not on the classpath".
    How can i solve this problem
    plz help me
    regards
    DeepaEdit the start-weblogic script. Near the bottom, you will see
    lines that create a CLASSPATH for the weblogic server. Add a
    script line that adds the mysql driver to the classpath there.
    Joe

  • JTable problem plz help me urgent

    sir
    i carefully read the swing tutorial for JTable for the purpose
    of rendring specially header rendring.
    first u see the code
    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.*;
    import javax.swing.border.*;
    import java.util.*;
    import javax.swing.table.*;
    public class Myscrollpane extends JScrollPane
    ImageIcon icon=new ImageIcon("images/beach1.jpg");
    Image img;
    int w,h,wi,hi;
    TableColumn column = null;
    /*Vector cols=new Vector();
    cols.addElement("Company Code");
    cols.addElement("Company Name");
    String[] names = {"Company Code", "Company Name"};
    DefaultTableModel model=new DefaultTableModel(names,0);
    JTable table=new JTable(model);
    LogoViewport vp;//custom class extends with JViewport
    Myscrollpane(int width,int height)
    vp= new LogoViewport(width,height);
    setOpaque(false);
    setMinimumSize(new Dimension(width,height));
    setPreferredSize(new Dimension(width,height));
    setSize(350,125);
    ///////////here r the table methods to control /////////////////////
    table.setPreferredScrollableViewportSize(new Dimension(width,height));
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF );
    table.getTableHeader().setReorderingAllowed(false);
    table.setBackground(new Color(245,235,237));
    table.setForeground(Color.black);
    table.setOpaque(true);
    table.setEnabled(false);
    table.setFont(new java.awt.Font("Dialog", Font.ITALIC, 12));
    table.setGridColor(Color.pink);
    table.setRowHeight(22);
    table.setSelectionBackground(Color.lightGray);
    DefaultTableCellRenderer renderer=new DefaultTableCellRenderer();
    TableColumn code=table.getColumnModel().getColumn(0);
    renderer.setBackground(Color.red);
    ????//if i use the setIcon method then the data comes from the database
    ????//is not shown because the icon paint above the data.
    code.setCellRenderer(renderer);
    TableCellRenderer headerRenderer = table.getTableHeade.().getDefaultRenderer();
    TableColumn column1=null;
    ???//i use this to change the color of header column but it is not work
    for (int j = 0; j < 2; j++) {
    column1 = table.getColumnModel().getColumn(j);
    Component comp = headerRenderer.getTableCellRendererComponent(
    null, column1.getHeaderValue(),
    false, false, 0, 0);
    comp.setBackground(Color.red);
    ???//if i use following it also not work
    TableCellRenderer headerRenderer = table.getTableHeader().
    getDefaultRenderer();
    if (headerRenderer instanceof DefaultTableCellRenderer) {
    ((DefaultTableCellRenderer)headerRenderer).setBackground(Color.red);}
    for (int i = 0; i <=1; i++)
    column = table.getColumnModel().getColumn(i);
    if (i == 0) {
    column.setPreferredWidth(100);
    else
    column.setPreferredWidth(225);
    vp.setView(table);
    this.setViewport(vp);
    plz help me with the code.
    i also want to draw the image on the table with the use of DefaultTabel
    Model and data set from the data base.Initally no row is shown.
    plz help me
    shown(???) are the quesstion which i am unable to solve.
    thanks in advance.

    Formatting the code makes it easier to read, which means more people may attempt to read your code and answer your questions. Click on the "Help" link at the top of the page.
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class TableHeader extends JFrame
        public TableHeader()
            JTable table = new JTable(5, 5);
            table.setPreferredScrollableViewportSize(table.getPreferredSize());
            JScrollPane scrollPane = new JScrollPane( table );
            getContentPane().add( scrollPane );
            table.getTableHeader().setBackground( Color.red );
        public static void main(String[] args)
            TableHeader frame = new TableHeader();
            frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
            frame.pack();
            frame.setLocationRelativeTo( null );
            frame.setVisible(true);
    }

  • JTable problem plz help me urgent withDefault TableModel

    sir
    i carefully read the swing tutorial for JTable for the purpose
    of rendring specially header rendring.
    first u see the code
    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.*;
    import javax.swing.border.*;
    import java.util.*;
    import javax.swing.table.*;
    public class Myscrollpane extends JScrollPane {
    ImageIcon icon=new ImageIcon("images/beach1.jpg");
    Image img;
    int w,h,wi,hi;
    TableColumn column = null;
    String[] names = {"Company Code", "Company Name"};
    DefaultTableModel model=new DefaultTableModel(names,0);
    JTable table=new JTable(model);
    LogoViewport vp;//user class extends with JViewport
    Myscrollpane(int width,int height){
    vp= new LogoViewport(width,height);
    setOpaque(false);
    setMinimumSize(new Dimension(width,height));
    setPreferredSize(new Dimension(width,height));
    setSize(350,125);
    ///////////here r the table methods tocontrol /////////////////////
    table.setPreferredScrollableViewportSize(new Dimension width,height));
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF );
    table.getTableHeader().setReorderingAllowed(false);
    table.setBackground(new Color(245,235,237));
    table.setForeground(Color.black);
    table.setOpaque(true);
    table.setEnabled(false);
    table.setFont(new java.awt.Font("Dialog", Font.ITALIC, 12));
    table.setGridColor(Color.pink);
    table.setRowHeight(22);
    table.setSelectionBackground(Color.lightGray);
    DefaultTableCellRenderer renderer=new DefaultTableCellRenderer();
    TableColumn code=table.getColumnModel().getColumn(0);
    renderer.setBackground(Color.red);
    //if i use the setIcon method then the data comes from the database is
    //not shown because the icon paint above the data.Iwant to paint the
    //image on the table dynamically means as table populated the image is
    //paint on the table means no fix no of rows.How can i
    //do.
    code.setCellRenderer(renderer);
    TableCellRenderer headerRenderer = table.getTableHeade.().getDefaultRenderer();
    TableColumn column1=null;
    //i use this to change the color and paste icon of header column
    //but it is not work
    for (int j = 0; j < 2; j++) {
    column1 = table.getColumnModel().getColumn(j);
    Component comp = headerRenderer.getTableCellRendererComponent(null, column1.getHeaderValue(), false, false, 0, 0);
    comp.setBackground(Color.red);
    comp.setIcon(new ImageIcon("myimage.gif")); }
    //if i use following it also not work
    TableCellRenderer headerRenderer = table.getTableHeader().getDefaultRenderer();
    if (headerRenderer instanceof DefaultTableCellRenderer) {((DefaultTableCellRenderer)headerRenderer).setBackground(Color.red);} vp.setView(table);
    this.setViewport(vp);
    }plz help me with the code.
    stated as above i also want to draw the image on the table with the use of DefaultTabel
    Model and data set from the data base.Initally no row is shown.
    plz help me
    thanks in advance

    import java.awt.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class TableHeader extends JFrame
        public TableHeader()
            Object[] columnNames =
                new ImageIcon("copy16.gif"),
                "Some Text",
                new ImageIcon("add16.gif")
            //  Columns headings are cast to a String when created automatically.
            //  We want Icons, so use a special renderer and create the columns manually
            JTable table = new JTable();
            table.getTableHeader().setDefaultRenderer( new HeaderRenderer() );
            for (int i = 0; i < columnNames.length; i++)
                TableColumn newColumn = new TableColumn(i);
                newColumn.setHeaderValue( columnNames[i] );
                table.addColumn(newColumn);
            table.setPreferredScrollableViewportSize(table.getPreferredSize());
            JScrollPane scrollPane = new JScrollPane( table );
            getContentPane().add( scrollPane );
        class HeaderRenderer extends DefaultTableCellRenderer
            public Component getTableCellRendererComponent(
                JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col)
                setBorder(UIManager.getBorder("TableHeader.cellBorder"));
                setHorizontalAlignment(CENTER);
                //  color each cell
                if (col == 1)
                    setBackground( Color.yellow );
                else
                    setBackground( Color.green );
                //  display text or icon
                if (value instanceof Icon)
                    setIcon( (Icon)value );
                    setText( "" );
                else
                    setIcon( null );
                    setText((value == null) ? "" : value.toString());
                return this;
        public static void main(String[] args)
            TableHeader frame = new TableHeader();
            frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
            frame.pack();
            frame.setLocationRelativeTo( null );
            frame.setVisible(true);
    }

  • Problem PLZ Help me

    Hi Guys,
    I have a problem to make a developer application Client/Server.
    When i install forms Runtime on the Client`s computer and i open the application, i get the error that he can`t find the menu and the libraries.
    The menu path is for example on my computer F:\s3\Salesmenu
    But on the client it can be a different path an then he can`t find the menu.
    Now the properties for the main form are:
    Menu module f:\s3\Salesmenu
    Initial menu Salemenu
    Does anyone know how to fix this problem for example:
    1) by let the program search for the menu.
    2) .....
    Plz Help
    Vincent

    set your FORMS60_PATH on the client to Formspath;libpath;menupath so it looks in every dir named in the path.

  • Big Problem, PLZ HELP

    So, when i click on the itunes shortcut, which has the same icon as the Apple Software Updater, I get a box that says that iTunes has encountered a problem and needs to close. We are sorry for the inconvenience. I hit send once and sent the error report, and then restarted my computer to see if that would help. It didnt, so, now i cant access itunes this is a major problem cause i have all my songs on this computer. I also tried to plug in my ipod and see if that would make it load.
    I installed iTunes 7.0 on my laptop, the exact same way, and i works on my laptop, but not on my computer.
    PLZ HELP ME

    ok this is what i did when that happened to me. i uninstalled quicktime then went here: http://www.apple.com/quicktime/win.html and reinstalled the latest version :0)

  • Nokia n79 problem Plz Help!

    Hello!My nokia just stuck,or hang in(i dont now english good) but i cant do enything.Evry button just dont work only at start when i write my pi(and somethimes then too).Works only power button.Its weard.Plz help.Somethimes a whole day are no problems somhetimes a whol day.

    hey ivee n everyone else .. i'm facing the same problem.. n i need to fix this problem myself..
    my n79 gets hang constantly nowadays.. i've used this phone for 1 year plus now so warranty's no more..... none of the buttons on the keypad works when it gets hang.. onli the power button is functioning.. now it's gettin worse .. it even hangs before i insert my pincode... i cant sms, call , or anything.. it hangs after i pressed a few buttons..
    so ivee u've fixed ur n79 youself right..? umm.. can u explain to me wat a smallboard is? is that the board at the lower part of the keypad where u can see buttons underneath the white layer? and is that board expensive?
    pls reply asap anyone.. urgent

  • N79 hanging problem plz help....

    while unlocking the keypad of my n79 sometimes the phone gets hanged then i have to take the battery out and then again switch on the phone........plz help me how to get rid of this problem???

    I have also same problem with my Nokia N79, I just cancelled sensor for automatic themes from cover. Just open back cover & stick some paper or plastic cello tape on four hole marks of covers wich r sensor for automatic themes to change colour of back cover same as theme colour. From 2 days I feel my mobile working fine without hanging ! so try it, all the best.

  • Bluetooth connection problem plz help...

    hi everyone, just bought a new pearl 9105. everything works fine and even bluetooth... through which i can transfer data from blackberry to other mobiles(samsung,sony ericsson)... but the problem is i could not recieve data from other mobiles.i should get contacts list from the other mobiles... but due to this problem i couldnt. plz help me out..

    The best way to receive a file from another device via bluetooth is to go to Media, then press Menu, choose Receive Using Bluetooth, waiting for connection will be display, then send from the other device. It should work without hassle.

  • Applet problem plz HELP

    Hi all,
    I have a problem when I am trying to run a jar file from an applet. The jar is for remote desktop application. Jrdp.jar.
    And the Exception is���.
    Exception in thread "Thread-6" java.security.AccessControlException: access denied (java.util.PropertyPermission gnu.posixly_correct read)
    at java.security.AccessControlContext.checkPermission(Unknown Source)
    at java.security.AccessController.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkPropertyAccess(Unknown Source)
    at java.lang.System.getProperty(Unknown Source)
    at gnu.getopt.Getopt.<init>(Getopt.java:617)
    at gnu.getopt.Getopt.<init>(Getopt.java:581)
    at net.propero.rdp.Rdesktop.main(Rdesktop.java:290)
    at net.propero.rdp.applet.RdpThread.run(RdpApplet.java:190)
    can any one suggest me what I have to do???? Plz give your valuable suggestion in that matter. Should I have to do any thing in java.policy file. In that case what would be the syntax and what have allow. If possible plz help me out.
    Thanking you,
    With regards
    Shibaji Sabyal

    Try googling on how to sign your applet. The error you're getting can usually be solved by signing it.

  • Package Problem : Plz help

    I've make two classes named First.java and Second.java in e:\javafiles\test\vg folder
    package vg;
    public class First
              public int m = 100;
              public int n = 200;
    package vg;
    public class Second
              public static void me0()
                   System.out.println("Stupid cant u see the value of m is zero");
              public static void mgrn()
                   System.out.println("Yaar m is greater than n");
              public static void neven()
                   System.out.println("The value of n is Even");
    and a Third class
    import vg.*;
    public class Last
              public static void main(String robert[])
                   Second d = new Second();
                   First f = new First();
                   if(f.m==0)
                        d.me0();
                   if(f.m>f.n)
                        d.mgrn();
                   if((f.n%2)==0)
                        d.neven();
                   else
                        System.out.println("The value of n is Odd");
    Now the problem is that if I put the Last.java at e:\javafiles\test and compile it , it works fine but if I put the Last.java anywhere else e.g at e:\javafiles and try to compile it it does not works and gives error
    E:\JavaFiles>javac Last.java
    Last.java:1: package vg does not exist
    import vg.*;
    even if I change classapth variable as E:\javafiles\test or even E:\javafiles\test\vg
    plz help me in this regard

    You need to change where it is trying to find the 'vg' package. So, if your Last.java is in e:\javafiles, then you need to
    import test.vg.*
    e.g.
    import test.vg.*;           // Change this line
    public class Last
              public static void main(String robert[])
                   Second d = new Second();
                   First f = new First();
                   if(f.m==0)
                        d.me0();
                   if(f.m>f.n)
                        d.mgrn();
                   if((f.n%2)==0)
                        d.neven();
                   else
                        System.out.println("The value of n is Odd");
    Alan

  • N95 maps problem plz help me

    please any body can solve my problem?
    i have n95
    when i open gps application
    then on the screen globe is not showning and no maps are showing on screen
    only city names are showed
    and after the closing of map application in apst there are type on screen
    saving maps and data
    but now nothing typed
    plz help me

    i am using latest firm ware
    and using old maps application bcoz new beta 2.0 not showing my accurate position in pakistan
    if i am in my city
    the maps application shows u r 10 km from your city
    but old version give me accurate position...

  • Storing emails offline in database problem plz help me

    hello friends all .
    i wana store all the emails which i get from INBOX folder in database i am using Microsoft Access 2000 for it the below code get all the mails from INBOX and are stored in Array now plz some one help and send a code to store each field of message in data base..
    my database table name is mails
    Fields name -------------------Data Type
    mailid ----------------------- Autonumber
    from -------------------------- Text max length 255 chars (avaliable)
    to ---------------------------- Text max length 255 chars (avaliable)
    bcc --------------------------- Text max length 255 chars (avaliable)
    cc ---------------------------- Text max length 255 chars (avaliable)
    subject ------------------------ Text max length 255 chars (avaliable)
    attachments -------------------- Text max length 255 chars (avaliable)
    now what i want is to store the path of attachments store in directory
    Properties props = new Properties();
    String host = pop3.getText ();
    String provider = "pop3";
    try {
    Session session = Session.getDefaultInstance (props,
    new MailAuthenticator());
    Store store = session.getStore (provider);
    store.connect (host,null,null);
    Folder inbox = store.getFolder ("INBOX");
    if (inbox== null){
    System.out.println ("no inbox");
    inbox.open (Folder.READ_ONLY);
    Message[] messages= inbox.getMessages ();
    for (int i =0 ; i<messages.length;i++){
    messages.writeTo(System.out)
    // what should i do here to store each message in database plz help me
    inbox.close (false);
    store.close ();
    catch(Exception ep){
    ep.printStackTrace();
    i'll be very thankfull plz help i try my best but didnt get success plz plz ! send a working code which i can learn and implement or send any file which do this work so that i can get help .
    thank you

    Unfortunately what you are trying to do is a little more complicated than just posting some code.
    To get the message content and any attachments you need to "parse" the MIME message you get from the store. An email will (should) be a multipart mime construct. You need to get all the "Parts" out of the message and put them into your relevant database fields.
    The "header" elements can be obtained just using the methods of the Message objects you are getting back. Have a look at the javadoc for the javax.mail.Message abstract class.
    As for example code, here's some old code I had lying around which parses a multipart message to get the various parts.
    There is a sample "main" method which should explain how it works:
    import javax.mail.*;
    import javax.mail.internet.*;
    import java.util.*;
    import java.io.*;
    * <p>Title: </p>
    * <p>Description: Parses a mime message to get the relevant parts.<BR>
    * <p>Copyright: Copyright (c) 2002</p>
    * @author Jason Polites
    * @version 1.0
    public class MimeMessageParser {
       * Gets the parts from the MimeMessage
       * Use null contentType to ignore
       * Use null disposition to ignore
      public static void getParts(List parts, Part p, String contentType, String disposition)
          throws MessagingException, IOException
        Object content = p.getContent();
        String currentDisposition = p.getDisposition();
        String currentContentType = p.getContentType();
        // now we need to check if the part was a multipart...
        if(content instanceof Multipart)
          Multipart mp = (Multipart)content;
          // Now we need to delve into the parts
          for(int i=0;i<mp.getCount();i++)
            getParts(parts, mp.getBodyPart(i), contentType, disposition);
        // check to the contentType
        if(contentType == null) {
          // we don't need to check
          if(disposition == null) {
            // no need to check
            // add the part
            parts.add(p);
            //index++;
          else if(currentDisposition != null && currentDisposition.startsWith(disposition))
            // add the part
            parts.add(p);
        else if(p.isMimeType(contentType)) {
          // Check the disposition
          if(disposition == null) {
            // no need to check
            // add the part
            parts.add(p);
          else if(currentDisposition != null && currentDisposition.startsWith(disposition))
            // add the part
            parts.add(p);
       * Gets the parts which match any of the dispositions
       * @param parts
       * @param contentTypes
       * @param disposition
       * @return
      public static List getMultiplePartsFromList(List parts, String contentType, String[] dispositions)
          throws IOException, MessagingException
        List matchedParts = null;
        for(int i = 0; i < dispositions.length; i++) {
          if(matchedParts == null) {
            matchedParts = getPartsFromList(parts, contentType, dispositions);
    else
    matchedParts.addAll(getPartsFromList(parts, contentType, dispositions[i]));
    return matchedParts;
    public static List getPartsFromList(List parts, String contentType, String disposition)
    throws MessagingException, IOException
    LinkedList matchedParts = new LinkedList();
    Part p = null;
    Object content = null;
    String currentDisposition = null;
    String currentContentType = null;
    for(int i = 0; i < parts.size(); i++) {
    p = (Part)parts.get(i);
    content = p.getContent();
    currentDisposition = p.getDisposition();
    currentContentType = p.getContentType();
    if(contentType == null) {
    // we don't need to check
    if(disposition == null) {
    // no need to check
    matchedParts.add(p);
    else if(currentDisposition != null && currentDisposition.startsWith(disposition))
    matchedParts.add(p);
    else if(p.isMimeType(contentType)) {
    // Check the disposition
    if(disposition == null) {
    // no need to check
    matchedParts.add(p);
    else if(currentDisposition != null && currentDisposition.startsWith(disposition))
    matchedParts.add(p);
    return matchedParts;
    public static void main(String[] args) {
    try {
    File email = new File("C:\\test.eml");
    InputStream source = null;
    MimeMessage message = null;
    MimeMessageParser parser = null;
    parser = new MimeMessageParser();
    // First, construct an inputstream for the message file
    source = new FileInputStream(email);
    String host = "localhost";
    boolean sessionDebug = false;
    // Create some properties and get the default Session.
    Properties props = System.getProperties();
    props.put("mail.host", host);
    props.put("mail.transport.protocol", "smtp");
    Session mailSession = Session.getDefaultInstance(props, null);
    // Set debug on the Session so we can see what is going on
    // Passing false will not echo debug info, and passing true
    // will.
    mailSession.setDebug(sessionDebug);
    message = new MimeMessage(mailSession, source);
    // parse the message...
    LinkedList parts = new LinkedList();
    MimeMessageParser.getParts(parts, message, null, null);
    Part p;
    Attachment a;
    String[] dispositions = new String[2];
    dispositions[0] = MimeMessage.INLINE;
    dispositions[1] = MimeMessage.ATTACHMENT;
    List attachments = MimeMessageParser.getMultiplePartsFromList(parts, null, dispositions);
    //Just for testing.. print out the parts...
    for(int i = 0; i < attachments.size(); i++) {
    System.out.println("Part " + i + " content type: " + ((Part)attachments.get(i)).getContentType());
    catch (Exception ex) {
    ex.printStackTrace();

Maybe you are looking for

  • Difference in PO and GR delivery costs for Import PO

    Hi,            Good Morning. I have created Imported PO. At item level, i have assigned INR 100 as CHA charges. Now it has been converted to 2.12USD. Then while doing the GR, in accounting document, it is updating CHA charges as 99.72. Then what abou

  • I have a question about free hand crop on PhotoshopCC

    I have a pic that I want to take a specific shape from, but the colors are numerous and complex so the magic wand wont work. Is there a way to free hand crop or select only the odd shape with a drawing option?????? I want to snip just the loader mach

  • Can I install Java 2 SDK 1.4.2 with NetBeans bundle on a Laptop?

    I'm new to programming and I'm getting an Alienware notebook with WindowsXP in a few months. I just want to be sure I can install and use Java on it. Any recommendations for literature on programming for beginners would be great too. Something easy t

  • SendRedirect( )

    Hi , I am using sendRedirect( ) method in jsp . ( redirecting to a servlet to generat an image) . It works on most of the places , I tested. On some machine it's not working tough the browser version is same (IE 5.00) , but it works in Netscape on sa

  • Custome SCHEMA  Files

    Can anybody tell how to import the custom schema on directory server 5.1 SP1 on solaris 8. I created a ldif file contains my custom attributes and objectclass and stored in "server-root/config/schema/" directory, i do not want to user 99user.ldif fil