How to save contents of a JTable? Pls Help

Can someone tell me how can I save the contents of a table in a file and load them back after I click a load file button in menuBar.
Any help would be appriciated.

Actually, I first wanted to get Window Pop-up asking for a file name and then after file name is entered user should click on save button and then all the data entered in the table should be saved.
thanks

Similar Messages

  • How  to  save  content of a  whole  swing  page

    Hi everyone ..
    can any of u tell me ,how to save contents of a java swing page in a single file with all components viz . textfield,textarea,JTable,JPanel etc .. with their respective formatting ie.e Font,Color etc ..
    Plz let me know it soon .. its very urgent ..
    Can I save it as Screenshot or Jpeg Image .. or how to go about it .
    Mohit

    Sure: see below!
    WARNING: this code will not compile as is because it uses some other classes from my personal code library (FileUtil & StringUtil). The particular methods of those classes which are used below are trivial methods that anyone can write, which is is why I have not posted them as well. So, to get the code below to compile, you can
    a) write your own versions of these classes or
    b) simply add the necessary methods to this class or
    c) simply comment out their usage (in the case of StringUtil, which is just used for arg checking)
    But if you still want me to post them, then I can post the relevant fragments of those classes.
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import java.io.*;
    import javax.imageio.*;
    import javax.swing.*;
    import bb.io.FileUtil;
    import bb.util.StringUtil;
    * Class which supports taking screen shots of the entire desktop, AWT Components, or Swing JComponents.
    * This functionality is implemented in a series of <code>take</code> methods, each of which returns a BufferedImage.
    * This class also offers convenience <code>write</code> methods for storing BufferedImages to files.
    * <p>
    * The images taken by this class should be the precise images seen on the screen.
    * <b>However, the images written to files may deviate from the originals.</b>
    * One obvious cause is limitations of the chosen file format (especially with lossy formats like jpeg).
    * A subtle issue can occur, however, even when using lossless formats like png:
    * if the file is subsequently opened by another application,
    * that application may rescale the image, which can often cause visible artifacts.
    * <blockquote>
    *     To see this last problem on Windows XP,
    *     call {@link #take()} which returns an image of the entire desktop and write it to a file,
    *     and then open the file with XP's default graphics file viewer ("Windows Picture And Fax Viewer").
    *     This program shrinks the desktop image in order to fit it inside the program's window,
    *     and rescaling artifacts are readily seen, especially if the desktop image has any kind of text in it.
    *     If "Windows Picture And Fax Viewer" instead cropped the image or had a scroll pane, then this should not happen.
    * </blockquote>
    * <p>
    * Acknowledgement: this class was inspired by the program
    * <a href="http://www.discoverteenergy.com/files/ScreenImage.java">ScreenImage</a>.
    * Differences from the above program:
    * <ol>
    *  <li>this class uses {@link BufferedImage#TYPE_INT_ARGB} instead of {@link BufferedImage#TYPE_INT_RGB} in order to preserve alpha</li>
    *  <li>this class's {@link #formatNameDefault default image file format} is PNG instead of JPEG</li>
    *  <li>this class's <code>take</code> methods simply take snapshots and never have the side effect of writing image files</li>
    *  <li>this class added a version of <code>take</code> which can get a snapshot of a region of a Component</li>
    *  <li>
    *          when taking a snapshot of a region of a Component or JComponent,
    *          the Rectangle that specifies the region always has coordinates relative to the origin of the item
    *  </li>
    * </ol>
    * See also:
    * <a href="http://forum.java.sun.com/thread.jspa?forumID=57&threadID=597936">forum discussion #1 on screen shots</a>
    * <a href="http://forum.java.sun.com/thread.jspa?forumID=256&threadID=529933">forum discussion #2 on screen shots</a>
    * <a href="http://forum.java.sun.com/thread.jspa?forumID=57&threadID=622393">forum discussion #3 on screen shots</a>.
    * <p>
    * It might appear that this class is multithread safe
    * because it is immutable (both its immediate state, as well as the deep state of its fields).
    * However, typical Java gui code is not multithread safe, in particular, once a component has been realized
    * it should only be accessed by the event dispatch thread
    * (see <a href="http://java.sun.com/developer/JDCTechTips/2003/tt1208.html#1">Multithreading In Swing</a>
    * and <a href="http://java.sun.com/developer/JDCTechTips/2004/tt0611.html#1">More Multithreading In Swing</a>).
    * So, in order to enforce that requirement, all methods of this class which deal with components
    * require the calling thread to be the event dispatch thread.
    * See the javadocs of each method for its thread requirements.
    * <p>
    * @author bbatman
    public class ScreenShot {
         // -------------------- constants --------------------
         * Defines the image type for the BufferedImages that will create when taking snapshots.
         * The current value is {@link BufferedImage#TYPE_INT_ARGB}, which was chosen because
         * <ol>
         *  <li>the 'A' in its name means that it preserves any alpha in the image (cannot use the "non-A" types)</li>
         *  <li>the "_INT" types are the fastest types (the "BYTE" types are slower)
         * </ol>
         * @see <a href="http://forum.java.sun.com/thread.jspa?threadID=709109&tstart=0">this forum posting</a>
         private static final int imageType = BufferedImage.TYPE_INT_ARGB;
         * Default value for the graphics file format that will be written by this class.
         * The current value is "png" because the PNG format is by far the best lossless format currently available.
         * Furthermore, java cannot write to GIF anyways (only read).
         * <p>
         * @see <a href="http://www.w3.org/TR/PNG/">Portable Network Graphics (PNG) Specification (Second Edition)</a>
         * @see <a href="http://www.w3.org/QA/Tips/png-gif">GIF or PNG</a>
         * @see <a href="http://www.libpng.org/pub/png/">PNG Home Site</a>
         public static final String formatNameDefault = "png";
         // -------------------- take --------------------
         // desktop versions:
         * Takes a screen shot of the entire desktop.
         * <p>
         * Any thread may call this method.
         * <p>
         * @return a BufferedImage representing the entire screen
         * @throws AWTException if the platform configuration does not allow low-level input control. This exception is always thrown when GraphicsEnvironment.isHeadless() returns true
         * @throws SecurityException if createRobot permission is not granted
         public static BufferedImage take() throws AWTException, SecurityException {
              Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
              Rectangle region = new Rectangle(0, 0, d.width, d.height);
              return take(region);
         * Takes a screen shot of the specified region of the desktop.
         * <p>
         * Any thread may call this method.
         * <p>
         * @param region the Rectangle within the screen that will be captured
         * @return a BufferedImage representing the specified region within the screen
         * @throws IllegalArgumentException if region == null; region's width and height are not greater than zero
         * @throws AWTException if the platform configuration does not allow low-level input control. This exception is always thrown when GraphicsEnvironment.isHeadless() returns true
         * @throws SecurityException if createRobot permission is not granted
         public static BufferedImage take(Rectangle region) throws IllegalArgumentException, AWTException, SecurityException {
              if (region == null) throw new IllegalArgumentException("region == null");
              return new Robot().createScreenCapture( region );     // altho not currently mentioned in its javadocs, if you look at its source code, the Robot class is synchronized so it must be multithread safe, which is why any thread should be able to call this method
         // AWT Component versions:
         * Takes a screen shot of that part of the desktop whose area is where component lies.
         * Any other gui elements in this area, including ones which may lie on top of component,
         * will be included, since the result always reflects the current desktop view.
         * <p>
         * Only {@link EventQueue}'s {@link EventQueue#isDispatchThread dispatch thread} may call this method.
         * <p>
         * @param component AWT Component to take a screen shot of
         * @return a BufferedImage representing component
         * @throws IllegalArgumentException if component == null; component's width and height are not greater than zero
         * @throws IllegalStateException if calling thread is not EventQueue's dispatch thread
         * @throws AWTException if the platform configuration does not allow low-level input control. This exception is always thrown when GraphicsEnvironment.isHeadless() returns true
         * @throws SecurityException if createRobot permission is not granted
         public static BufferedImage take(Component component) throws IllegalArgumentException, IllegalStateException, AWTException, SecurityException {
              if (component == null) throw new IllegalArgumentException("component == null");
              if (!EventQueue.isDispatchThread()) throw new IllegalStateException("calling thread (" + Thread.currentThread().toString() + ") is not EventQueue's dispatch thread");
              Rectangle region = component.getBounds();
              region.x = 0;     // CRITICAL: this and the next line are what make region relative to component
              region.y = 0;
              return take(component, region);
         * Takes a screen shot of that part of the desktop whose area is the region relative to where component lies.
         * Any other gui elements in this area, including ones which may lie on top of component,
         * will be included, since the result always reflects the current desktop view.
         * <p>
         * Only {@link EventQueue}'s {@link EventQueue#isDispatchThread dispatch thread} may call this method.
         * <p>
         * @param component AWT Component to take a screen shot of
         * @param region the Rectangle <i>relative to</i> component that will be captured
         * @return a BufferedImage representing component
         * @throws IllegalArgumentException if component == null; component's width and height are not greater than zero; region == null
         * @throws IllegalStateException if calling thread is not EventQueue's dispatch thread
         * @throws AWTException if the platform configuration does not allow low-level input control. This exception is always thrown when GraphicsEnvironment.isHeadless() returns true
         * @throws SecurityException if createRobot permission is not granted
         public static BufferedImage take(Component component, Rectangle region) throws IllegalArgumentException, IllegalStateException, AWTException, SecurityException {
              if (component == null) throw new IllegalArgumentException("component == null");
              if (region == null) throw new IllegalArgumentException("region == null");
              if (!EventQueue.isDispatchThread()) throw new IllegalStateException("calling thread (" + Thread.currentThread().toString() + ") is not EventQueue's dispatch thread");
              Point p = new Point(0, 0);
              SwingUtilities.convertPointToScreen(p, component);
              region.x += p.x;
              region.y += p.y;
              return take(region);
         // Swing JComponent versions:
         * Takes a screen shot of <i>just</i> jcomponent
         * (no other gui elements will be present in the result).
         * <p>
         * Only {@link EventQueue}'s {@link EventQueue#isDispatchThread dispatch thread} may call this method.
         * <p>
         * @param jcomponent Swing JComponent to take a screen shot of
         * @return a BufferedImage representing jcomponent
         * @throws IllegalArgumentException if jcomponent == null
         * @throws IllegalStateException if calling thread is not EventQueue's dispatch thread
         public static BufferedImage take(JComponent jcomponent) throws IllegalArgumentException, IllegalStateException {
              if (jcomponent == null) throw new IllegalArgumentException("jcomponent == null");
              if (!EventQueue.isDispatchThread()) throw new IllegalStateException("calling thread (" + Thread.currentThread().toString() + ") is not EventQueue's dispatch thread");
              Dimension d = jcomponent.getSize();
              Rectangle region = new Rectangle(0, 0, d.width, d.height);
              return take(jcomponent, region);
         * Takes a screen shot of <i>just</i> the specified region of jcomponent
         * (no other gui elements will be present in the result).
         * <p>
         * Only {@link EventQueue}'s {@link EventQueue#isDispatchThread dispatch thread} may call this method.
         * <p>
         * @param jcomponent Swing JComponent to take a screen shot of
         * @param region the Rectangle <i>relative to</i> jcomponent that will be captured
         * @return a BufferedImage representing the region within jcomponent
         * @throws IllegalArgumentException if jcomponent == null; region == null
         * @throws IllegalStateException if calling thread is not EventQueue's dispatch thread
         public static BufferedImage take(JComponent jcomponent, Rectangle region) throws IllegalArgumentException, IllegalStateException {
              if (jcomponent == null) throw new IllegalArgumentException("jcomponent == null");
              if (region == null) throw new IllegalArgumentException("region == null");
              if (!EventQueue.isDispatchThread()) throw new IllegalStateException("calling thread (" + Thread.currentThread().toString() + ") is not EventQueue's dispatch thread");
              boolean opaquenessOriginal = jcomponent.isOpaque();
              Graphics2D g2d = null;
              try {
                   jcomponent.setOpaque( true );
                   BufferedImage image = new BufferedImage(region.width, region.height, imageType);
                   g2d = image.createGraphics();
                   g2d.translate(-region.x, -region.y) ;     // CRITICAL: this and the next line are what make region relative to component
                   g2d.setClip( region );
                   jcomponent.paint( g2d );
                   return image;
              finally {
                   jcomponent.setOpaque( opaquenessOriginal );
                   if (g2d != null) g2d.dispose();
         // -------------------- write --------------------
         * Writes image to a newly created File named fileName.
         * The graphics format will either be the extension found in fileName
         * or else {@link #formatNameDefault} if no extension exists.
         * <p>
         * Any thread may call this method.
         * <p>
         * @param image the BufferedImage to be written
         * @param fileName name of the File that will write image to
         * @throws IllegalArgumentException if image == null; fileName is blank
         * @throws IOException if an I/O problem occurs
         public static void write(BufferedImage image, String fileName) throws IllegalArgumentException, IOException {
              if (image == null) throw new IllegalArgumentException("image == null");
              if (StringUtil.isBlank(fileName)) throw new IllegalArgumentException("fileName is blank");
              File file = new File(fileName);
              String formatName = FileUtil.getExtension(file);
              if (formatName.length() == 0) formatName = formatNameDefault;
              write(image, formatName, file);
         * Writes image to file in the format specified by formatName.
         * <p>
         * Any thread may call this method.
         * <p>
         * @param image the BufferedImage to be written
         * @param formatName the graphics file format (e.g. "pnj", "jpeg", etc);
         * must be in the same set of values supported by the formatName arg of {@link ImageIO#write(RenderedImage, String, File)}
         * @param file the File that will write image to
         * @throws IllegalArgumentException if image == null; type is blank; file == null
         * @throws IOException if an I/O problem occurs
         public static void write(BufferedImage image, String formatName, File file) throws IllegalArgumentException, IOException {
              if (image == null) throw new IllegalArgumentException("image == null");
              if (StringUtil.isBlank(formatName)) throw new IllegalArgumentException("formatName is blank");
              if (file == null) throw new IllegalArgumentException("file == null");
              ImageIO.write(image, formatName, file);
         // -------------------- Test (inner class) --------------------
         * An inner class that consists solely of test code for the parent class.
         * <p>
         * Putting all the test code in this inner class (rather than a <code>main</code> method of the parent class) has the following benefits:
         * <ol>
         *  <li>test code is cleanly separated from working code</li>
         *  <li>any <code>main</code> method in the parent class is now reserved for a true program entry point</li>
         *  <li>test code may be easily excluded from the shipping product by removing all the Test class files (e.g. on Windoze, delete all files that end with <code>$Test.class</code>)</li>
         * </ol>
         * Putting all the test code in this inner class (rather than a shadow external class) has the following benefits:
         * <ol>
         *  <li>non-public members may be accessed</li>
         *  <li>the test code lives very close to (so is easy to find) yet is distinct from the working code</li>
         *  <li>there is no need to set up a test package structure</li>
         * </ol>
         public static class Test {
              public static void main(String[] args) throws Exception {
                   Gui gui = new Gui();
                   EventQueue.invokeLater( gui.getBuilder() );
                   new Timer(1000, gui.getTimerActionListener()).start();
              private static class Gui {
                   private Frame frame;
                   private TextField textField;
                   private JFrame jframe;
                   private JLabel jlabel;
                   private JPanel jpanel;
                   private int count = 0;
                   private Runnable getBuilder() {
                        return new Runnable() {
                             public void run() {
                                  System.out.println("Creating a Frame with AWT widgets inside...");
                                  frame = new Frame("ScreenShot.Test.main Frame");
                                  textField = new TextField();
                                  textField.setText( "Waiting for the screen shot process to automatically start..." );
                                  frame.add(textField);                              
                                  frame.pack();
                                  frame.setLocationRelativeTo(null);     // null will center it in the middle of the screen
                                  frame.setVisible(true);
                                  System.out.println("Creating a JFrame with Swing widgets inside...");
                                  jframe = new JFrame("ScreenShot.Test.main JFrame");
                                  jlabel = new JLabel(
                                       "<html>" +
                                            "To be, or not to be: that is the question:" + "<br>" +
                                            "Whether 'tis nobler in the mind to suffer" + "<br>" +
                                            "The slings and arrows of outrageous fortune," + "<br>" +
                                            "Or to take arms against a sea of troubles," + "<br>" +
                                            "And by opposing end them?" + "<br>" +
                                            "To die: to sleep; No more;" + "<br>" +
                                            "and by a sleep to say we end" + "<br>" +
                                            "The heart-ache and the thousand natural shocks" + "<br>" +
                                            "That flesh is heir to," + "<br>" +
                                            "'tis a consummation Devoutly to be wish'd." + "<br>" +
                                       "</html>"
                                  jpanel = new JPanel();
                                  jpanel.setBorder( BorderFactory.createEmptyBorder(20, 20, 20, 20) );
                                  jpanel.add(jlabel);
                                  jframe.getContentPane().add(jpanel);
                                  jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                                  jframe.pack();
                                  Point p = frame.getLocation();
                                  p.translate(0, frame.getSize().height  + 10);
                                  jframe.setLocation(p);
                                  jframe.setVisible(true);
                   private ActionListener getTimerActionListener() {
                        return new ActionListener() {
                             public void actionPerformed(ActionEvent evt) {
                                  try {
                                       switch (count++) {
                                            case 0:
                                                 displayMessage("Taking a screen shot of the entire desktop...");
                                                 ScreenShot.write( ScreenShot.take(), "desktop.png" );
                                                 break;
                                            case 1:
                                                 displayMessage("Taking a screen shot of the central rectangle of the desktop...");
                                                 Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
                                                 Rectangle region = getCenteredRectangle(d);
                                                 ScreenShot.write( ScreenShot.take(region), "desktopCenteredRectangle.png" );
                                                 break;
                                            case 2:
                                                 displayMessage("Taking a screen shot of the TextField...");
                                                 ScreenShot.write( ScreenShot.take(textField), "textField.png" );
                                                 break;
                                            case 3:
                                                 displayMessage("Taking a screen shot of the central rectangle of the TextField...");
                                                 d = textField.getSize();
                                                 region = getCenteredRectangle(d);
                                                 ScreenShot.write( ScreenShot.take(textField, region), "textFieldCenteredRectangle.png" );
                                                 break;
                                            case 4:
                                                 displayMessage("Taking a screen shot of the JLabel...");
                                                 ScreenShot.write( ScreenShot.take(jlabel), "jlabel.png" );
                                                 break;
                                            case 5:
                                                 displayMessage("Taking a screen shot of the central rectangle of the JLabel...");
                                                 d = jpanel.getSize();
                                                 region = getCenteredRectangle(d);
                                                 ScreenShot.write( ScreenShot.take(jpanel, region), "jpanelCenteredRectangle.png" );
                                                 break;
                                            default:
                                                 System.exit(0);
                                                 break;
                                  catch (Throwable t) {
                                       t.printStackTrace(System.err);
                             private void displayMessage(String text) {
                                  System.out.println(text);
                                  textField.setText(text);
                                  frame.pack();
                                  frame.invalidate();
                             private Rectangle getCenteredRectangle(Dimension d) {
                                  int x = d.width / 4;
                                  int y = d.height / 4;
                                  int width = d.width / 2;
                                  int height = d.height / 2;
                                  return new Rectangle(x, y, width, height);
    }

  • How to save content typed in textfield only as lowercase in repository?

    How to save content typed in textfield only as lowercase in repository?
    Suppose we have a textfield in a component dialog. Irrespective of how enduser enters the data in the textfield, lower/mixed/upper case, it should always be saved as lowercase in the repository.

    You have 2 options:
    * Frontend: You adjust the javascript, so the user can only enter lowercase characters
    * Server-side: Implement a SlingPostProcessor to change the data to lowercase before it is persisted (see http://sling.apache.org/apidocs/sling6/org/apache/sling/servlets/post/SlingPostProcessor.h tml)
    Jörg

  • How to undelete an inforecord ...pls help???

    how to undelete an inforecord ...pls help???

    Hi,
    Use Tcode ME15.
    Give the material , Vendor , Purcahse Organization,.
    If it is to be undeleted at Plant level give the Plant details adn excute.
    Uncheck and Save.
    Regards
    Give point if useful

  • I have updated my ipod touch to ios5 and it is saying that the device is not registered in apple developers program.I have a back up fle in itunes and itunes is not prompting for restore.how can i restore my pod?pls help me to restore my ipod .am worried

    I have updated my ipod touch to ios5 and it is saying that the device is not registered in apple developers program.I have a back up fle in itunes and itunes is not prompting for restore.how can i restore my pod?pls help me to restore my ipod .am worried as it my new ipod and am not able to restore it.pls help.

    i have done that .:(..PLs help me restoring it to older version.though i have a back up file.in itunes..am not able to restore it.as itunes is not asking for resotre option..pls help me

  • Hi! I accidentally deleted my app store from the phone....how to retrieve it back...pls help me...just using the iphone

    Hi everyone
    I am a new user of iphone 4...i've accidentally deleted the app store from the iphone...pls tell me how to retrieve it back...pls help...tq

    To restore the missing App Store Icon, or other original Apple Icons on the iPhone, go to Settings / General / Reset (Don't worry, you will be presented with a number of options concerning resetting before anything happens. The iPhone will NOT reset just by selecting this option).
    Choose "Reset Home Screen Layout". This will restore the App Store Icon as well as other Apple Icons you may have removed or placed into folders.
    Please note. This also removes any folders you have set up and rearranges all of the apps you have, so it takes awhile to put everything back where it was.
    Unfortunately, I did not capture the placement of my Icons, so I had to recreate from memory...not that big a deal. If you elect to follow this procedure, make a note of where all of your icons are placed and then proceed.
    I followed links that talked about restoring through iTunes...never could make anything like that work. This is a quick and simple fix.

  • HT1267 I lost my Iphone3G. I don't have any tracking app. in cell.How can I find my phone. Pls. help me out..

    I lost my Iphone3G. I don't have any tracking app. in cell.How can I find my phone. Pls. help me out..

    In your situation as you describe it, all you can do is physically look for it.  There is no other way to locate it.  Sorry.
    Hope this helps

  • Lost a shortcut for one of my apps but the app is on my phone when i go into the app store under purchased how do i create a shortcut again, pls help iphone 4

    lost a shortcut for one of my apps but it shows up in the app store as purchased how do I get the shortcut back, pls help iphone 4

    Hi newyorker2014,
    I apologize, I'm a bit unclear on the exact nature of your issue. If you are no longer seeing the app in question on your iPhone, but it is showing as purchased on the App Store, you should be able to redownload it directly. You may find the following article helpful:
    Download past purchases
    http://support.apple.com/kb/ht2519
    Regards,
    - Brenden

  • How to get date and time? pls help~   ~.~

    i tried to get time and date, but dint noe hw to get it.. anyone knows hw to get it? pls help mi ~.~
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.util.Calendar.*;
    public class Login extends JFrame
    private JFrame mainFrame;
    private JPanel p1;
    private JLabel lblUserId, lblPassword;
    private JTextField tf1, tf2;
    private JButton btnLogin, btnClear;
    public Login()
         mainFrame=new JFrame();
         mainFrame.setTitle("Student Attendance System");
         mainFrame.setSize(400,200);
         mainFrame.setLocation(100,100);
         mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         p1=new JPanel();
         p1.setLayout(new GridLayout(3,2));
         lblUserId=new JLabel("User ID");
         lblPassword=new JLabel("Password");
         tf1=new JTextField(20);
         tf2=new JTextField(20);
         btnLogin=new JButton("Login");
         btnLogin.addActionListener(new ButtonHandler());
         btnClear=new JButton("Clear");
         btnClear.addActionListener(new ButtonHandler());
         p1.add(lblUserId);
         p1.add(tf1);
         p1.add(lblPassword);
         p1.add(tf2);
         p1.add(btnLogin);
         p1.add(btnClear);
         mainFrame.add(p1);
    mainFrame.setVisible(true);
    //inner class event handler
    public class ButtonHandler implements ActionListener
         public void actionPerformed(ActionEvent evt)
              Calendar rightNow = Calendar.getInstance();
              if(evt.getSource()==btnLogin)
                   String login=tf1.getText();
                   String password=tf2.getText();
                   JOptionPane.showMessageDialog(mainFrame, "Student ID "+login+" Login at " + rightNow ,
                   "Response", JOptionPane.PLAIN_MESSAGE);
              if(evt.getSource()==btnClear)
                   tf1.setText("");
                   tf2.setText("");
    public static void main(String []args)
         JFrame.setDefaultLookAndFeelDecorated(true);
         Login l=new Login();
    }

    First off, from http://www.catb.org/~esr/faqs/smart-questions.html
    h1. How To Ask Questions The Smart Way:
    h3. Write in clear, grammatical, correctly-spelled language
    More generally, if you write like a semi-literate boob you will very likely be ignored. So don't use instant-messaging
    shortcuts. Spelling "you" as "u" makes you look like a semi-literate boob to save two entire keystrokes. Worse: writing like
    a l33t script kiddie hax0r is the absolute kiss of death and guarantees you will receive nothing but stony silence (or, at best,
    a heaping helping of scorn and sarcasm) in return.
    Next, use a SimpleDateFormat object. You can use it directly or use a date format string to tell it how you want your date string formatted. The API will give you lots of information on how to use this. Note that you'll have to translate the Calendar object to a date object via the getTime() method:
        class ButtonHandler implements ActionListener
            public void actionPerformed(ActionEvent evt)
                Calendar rightNow = Calendar.getInstance();
                //** use SimpleDateFormat
                SimpleDateFormat dateFormat = new SimpleDateFormat();
                String dateString = dateFormat.format(rightNow.getTime());
                if (evt.getSource() == btnLogin)
                    String login = tf1.getText();
                    String password = tf2.getText();
                    JOptionPane.showMessageDialog(mainFrame, "Student ID " + login
                            + " Login at " + dateString,
                            "Response",
                            JOptionPane.PLAIN_MESSAGE);
                if (evt.getSource() == btnClear)
                    tf1.setText("");
                    tf2.setText("");
        }Finally, when posting your code, please use code tags so that your code will retain its formatting and be readable. To do this, either use the "code" button at the top of the forum Message editor or place the tag &#91;code] at the top of your block of code and the tag &#91;/code] at the bottom, like so:
    &#91;code]
      // your code block goes here.
    &#91;/code]

  • JTable pls help!

    Hi guys, i basically need to retrieve some data into a table from the database(mySql). but the data just cant be out. i need help from you all :).
    basically i have a form package, entity package, controller package, sqlAction package(where it calls things form the sql) and lastly dbController package. pls help me to see what have i miss out or done wrong, thanks a million!
    Form Package:
    package form;
    import javax.swing.*;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.JLabel;
    import javax.swing.JTextField;
    import sqlAction.EventLogAction;
    import controller.EventLogController;
    import entity.EventLog;
    private JTable getJTable_viewLog() {
              if (jTable_viewLog == null) {
                   jTable_viewLog = new JTable();
                   int row = 0;
                   int col = 0;
         String [] colName = {"Event ID", "Source","Event Description","Date Time", "IP"};
                    EventLog newEventLog = new EventLog();
                       EventLogController EventLogController = new EventLogController();
                  for (int i =0; i < row; i++) {
                                  for (int j = 0; j < col; j++) {
                                data[i][j] = newEventLog.getEID();
                                                    data[i][j] = newEventLog.getESource();
                                          data[i][j] = newEventLog.getEEvent();
                                          data[i][j] = newEventLog.getEDateTime();
                                          data[i][j] = newEventLog.getEIPAdd();
                             EventLogAction e = new EventLogAction();
                            e.getViewLog(newEventLog);
                   jTable_viewLog = new JTable(new DefaultTableModel(data,colName)){
                        * Prevent table from being edited.
                        private static final long serialVersionUID = 1L;
                        public boolean isCellEditable(int row, int col) { return false; }
                   jTable_viewLog.setBounds(new java.awt.Rectangle(27,30,450, 230));
              return jTable_viewLog;
              }Entity Package:
    package entity;
    public class EventLog {
         private String eID;
         private String eSource;
         private String eEvent;
         private String eDateTime;
         private String eIPAdd;
         public String getEID() {
              return eID;
         public void setEID(String eid) {
              eID = eid;
         public String getESource() {
              return eSource;
         public void setESource(String source) {
              eSource = source;
         public String getEEvent() {
              return eEvent;
         public void setEEvent(String event) {
              eEvent = event;
         public String getEDateTime() {
              return eDateTime;
         public void setEDateTime(String dateTime) {
              eDateTime = dateTime;
         public String getEIPAdd() {
              return eIPAdd;
         public void setEIPAdd(String add) {
              eIPAdd = add;
    }Controller Package:
    package controller;
    import sqlAction.EventLogAction;
    import entity.EventLog;
    public class ViewEventLogController {
    public void processGetViewLog(String eID,
                   String eSource,
                   String eEvent,
                   String eDateTime,
                   String eIPAdd)
              EventLog viewEve = new EventLog();
              EventLogAction va = new EventLogAction();
              viewEve.setEID(eID);
              viewEve.setESource(eSource);
              viewEve.setEEvent(eEvent);
              viewEve.setEDateTime(eDateTime);
              viewEve.setEIPAdd(eIPAdd);
              va.createEventPerform(viewEve);
    }sqlAction Package:
    package sqlAction;
    import dbController.DBController;
    import entity.EventLog;
    import java.sql.*;
    import java.util.*;
    public class EventLogAction {
         private String eID;
         private String eSource;
         private String eEvent;
         private String eDateTime;
         private String eIPAdd;
         private static EventLog newEventLog;
         public EventLogAction(){}
         public EventLogAction(String eID, String eSource, String eEvent, String eDateTime, String eIPAdd){           this.eID = eID;
              this.eSource = eSource;
              this.eEvent = eEvent;
              this.eDateTime = eDateTime;
              this.eIPAdd = eIPAdd;
    public EventLog getViewLog(EventLog viewEve){
              // Code to access db
              ResultSet rs = null;
              String dbQuery = "SELECT * FROM EventLog";
              DBController db = new DBController();
              System.out.println(dbQuery);
              db.setUp("cryptocrestSQL");
              rs = db.readRequest(dbQuery);
              try{
                   if (rs.next()){
                        String eID = rs.getString("eID");
                                                                    String eSource = rs.getString("eSource");
                        String eEvent = rs.getString("eEvent");
                        String eDateTime = rs.getString("eDateTime");
                        String eIPAdd = rs.getString("eIPAdd");;
                        EventLog el = new EventLog();
                        el.setEID(eID);
                        el.setESource(eSource);
                        el.setEEvent(eEvent);
                        el.setEDateTime(eDateTime);
                        el.setEIPAdd(eIPAdd);
              }catch (Exception e) {
                   e.printStackTrace();
              db.terminate();
              return newEventLog;
         public String getEID() {
              return eID;
         public void setEID(String eid) {
              eID = eid;
         public String getESource() {
              return eSource;
         public void setESource(String source) {
              eSource = source;
         public String getEEvent() {
              return eEvent;
         public void setEEvent(String event) {
              eEvent = event;
         public String getEDateTime() {
              return eDateTime;
         public void setEDateTime(String dateTime) {
              eDateTime = dateTime;
         public String getEIPAdd() {
              return eIPAdd;
         public void setEIPAdd(String add) {
              eIPAdd = add;
    }dbController Package:
    package dbController;
    * Program Name :     DBController.java
    * Description: DBController class to access the database.
    * Remember to set up the odbc using control panel.
    import java.sql.*;
    public class DBController {
         private Connection con;
         private ResultSet rs;
          * Method Name : setUp Input
          * Parameter : String (Data Source Name)
          * Purpose : Load the database driver and establish connection
          * Return : nil
         public void setUp(String dsn) {
              // load the database driver
              try {
                   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
              } catch (Exception e) {
                   System.out.println("Load driver error");
              // after loading the driver, establish a connection
              try {
                   String s = "jdbc:odbc:" + dsn;
                   con = DriverManager.getConnection(s, "", "");
                   System.out.println("connection is " + s);
              } catch (Exception e) {
                   e.printStackTrace();
          * Method Name : getColumnNames
          * Purpose : Obtain the column names of the result set
          * Return : Array of String
         public String[] getColumnNames() {
              String[] columnNames = null;
              try {
                   // Get result set meta data
                   ResultSetMetaData rsmd = rs.getMetaData();
                   columnNames = new String[rsmd.getColumnCount()];
                   // Get the column names; column indices start from 1
                   for (int i = 0; i < columnNames.length; i++) {
                        columnNames[i] = rsmd.getColumnName(i + 1);
              } catch (SQLException e) {
                   System.out.println("Error in getColumnNames() in DBController");
                   e.printStackTrace();
              return columnNames;
          * Method Name : readRequest
          * Input Parameter : String (database query)
          * Purpose : Obtain the result set from the db query
          * Return : resultset (records from the query)
         public ResultSet readRequest(String dbQuery) {
              ResultSet rs = null;
              System.out.println("DB Query: " + dbQuery);
              try {
                   // create a statement object
                   Statement stmt = con.createStatement();
                   // execute an SQL query and get the result
                   rs = stmt.executeQuery(dbQuery);
                   this.rs = rs;
              } catch (Exception e) {
                   e.printStackTrace();
              return rs;
          * Method Name : updateRequest Input Parameter : String (database query) Purpose :
          * Execute udpate using the db query Return : int (count is 1 if successful)
         public int updateRequest(String dbQuery) {
              int count = 0;
              // System.out.println("DB: " + dbQuery);
              try {
                   // create a statement object
                   Statement stmt = con.createStatement();
                   // execute an SQL query and get the result
                   count = stmt.executeUpdate(dbQuery);
              } catch (Exception e) {
                   e.printStackTrace();
              return count;
          * Method Name : terminate
          * Input Parameter : nil
          * Purpose : Close db conection
          * Return :nil
         public void terminate() {
              // close connection
              try {
                   con.close();
                   System.out.println("Connection is closed");
              } catch (Exception e) {
                   e.printStackTrace();
    } // end of DBControllerEdited by: Titus-tan on Jul 9, 2008 1:33 AM

    First off, your code style sucks. Consistent indentation would be nice. Don't mix spaces and tabs.
    package form;
    import javax.swing.*;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.JLabel;
    import javax.swing.JTextField;At this point, you've already imported JLabel and JTextField, no need to do it again.
    jTable_viewLog.setBounds(new java.awt.Rectangle(27,30,450, 230));Don't use setBounds to set the size of a Swing component, it'll just get wiped out when the layout manager does its thing.
    Use setPreferredSize instead.
    As for your database class, why are you passing queries into it? It should know how to pull the data out of the database and keep its queries internal.
    Not only will it be a cleaner design, you significantly reduce the possibility of executing bad queries. Also, PreparedStatements are almost always preferred
    over normal Statements, especially when combined with parameterized queries. Go google "Bobby Tables" if you don't understand why.
    Now then, what is it doing and what did you expect it to be doing?

  • Can anyone help me pls. , I deleted an app on my Ipod Touch, and It was deleted but when I connected my device on my computer and went to iTune "apps" , I saw the app I deleted and it says "install" .  Guys, how will I delete it permanently? Pls help me.

    Can anyone help me pls. , I deleted an app on my Ipod Touch, and It was deleted but when I connected my device on my computer and went to iTunes>"apps" , I still saw the app I deleted and it says "install" .  Guys, how will I delete it permanently? May you Pls help me. Thanks

    Just don't click install

  • Ontacts, notes, photos etc. lost. how can i restore all data? pls help

    i have lost all my contacts, notes, photos etc. when i sync my iphone with itunes. how can i restore all data? pls help

    Were you using iCloud? If you were, you can access all your stuff from iCloud.com and restore your phone to an icloud backup.

  • How to change lost mode passcode ? pls help

    how to change lost mode passcode ? pls help

    Hello Erkhes,
    You'll need to take the device to an authorized service center or Apple Store to restore access to your device.
    Note:   If you forget the passcode, or if you set an EFI firmware password on your Mac before it was lost, then lock it and later find it, you may need to take it to an authorized repair center to unlock it.
    iCloud: Use Lost Mode
    http://support.apple.com/kb/PH2700
    Cheers,
    Allen

  • How to save contents of two different rich edit box into single rtf file in windows 8.1 app

    Developer, I have requirement to save registration data into rtf file.. These can only be done by if I put rich edit box to fill the data.. Now if I am going to write the code for saving the data of different rich edit box into one particular file, it
    only saves the data of last rich edit box.. So plzz suggest that how can I save the contents of different rich edit box together into one rtf file.

    Ok Nishant, just did some quick research, since rtf file is unlike txt file, we cannot simply directly write some content to the rtf.
    You can try to find some third party code that can help you insert text into rtf file or you would like to load the content from rtf out to the richeditbox and merge them to one richeditbox and then save back to the file.
    You could like to see how to read/save rtf file sample from:
    RichEditBox class
    --James
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How to save contents of a structure into a field (of type LRAW) of a table?

    Hi,
    I've got a structure, with a few fields, some being char fields and some of type decimals and would like to save the contents into a field of a table, which is of type LRAW.
    I know that I've got to also update the table with the correct length of the value stored in LRAW, and have done that, but it seems to have lost the end bits of the LRAW field.
    Also, can I also find out how I can then retrieve the LRAW value after it's being saved? This needs to be done as later on, we would have to move the values from LRAW into the initial structure it came from.
    Thanks for your help!
    Regards,
    Adeline.

    Use MOVE command to move the contents of the stucture fields to the Wok area of the Internal table and then APPEND it to the Internal table

Maybe you are looking for

  • Error message in 'new" Acrobat 5.0

    I just installed a new (to me) edition of Acrobat 5.0, running on Windows XP. Whenever I click the desktop icon I get the following message: You cannot currently view Pdf files from within your web browser due to a configuration problem. Would you li

  • MAC OS 10.4 CRASHES AFTER HARD DRIVE UPGRADE

    I just bought a HITACHI hard drive for my iBook G4 1.33ghz. I installed the hard drive with no problems. After installing MAC OS X 10.4.2 & upgrading to 10.4.11, the OS keeps crashing, Ive done a APPLE HARDWARE TEST everything fine, Ive used disk uti

  • How to iterate the webservice Data control result set?

    Hi all, How to iterate the webservice Data control result set? I have an jsff page where I am displaying the single UserDetails by webservice DataContol. As per my design requirement I should iterate the DataControl resultSet to get the user details

  • How do I sort videos in iOS5?

    My videos are being scrambled.  They are different sets of numbered videos.  I tried putting them in playlists(iTunes), but they don't work in video app.

  • Searching a Remote Data Store

    We have a document storage system that we would like to integrate into our portal search. We seem to have two major issues to overcome: - the documents (metadata and data) are stored in a database- the security of the document management system is ex