Results 1 to 5 of 5
  1. #1
    ninjalord918 is offline Member
    Join Date
    Jul 2010
    Posts
    30
    Rep Power
    0

    Default How to set Table under Menu

    Hello all,

    I would like to know how to set my table under the menu. When I run the file in Eclipse, my table names are cut off. Please help.

    import javax.swing.*;

    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.GridLayout;
    import java.awt.event.*;

    public class main extends JPanel{

    public static void main (String[] args){
    String[] columnTitles = {"First Name",
    "Last Name",
    "Account Type",
    "Account Number",
    "Transaction Amount"};

    Object[][] data = {
    {"-", "-","-", "00000000", new Float(0.0)},
    {"Tuan", "-","-", "00000000", new Float(0.0)}};

    JFrame frame = new JFrame("MoneyNest4You");
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
    frame.setSize(900, 300);
    JMenuBar menubar = new JMenuBar();
    frame.setJMenuBar(menubar);

    JMenu file = new JMenu("File");
    menubar.add(file);
    JMenuItem exit = new JMenuItem("Exit");
    file.add(exit);

    JMenu help = new JMenu("Help");
    menubar.add(help);
    JMenuItem about = new JMenuItem("About");
    help.add(about);

    JTable table = new JTable(data, columnTitles);
    frame.add(table);

    class exitaction implements ActionListener{
    public void actionPerformed (ActionEvent e) {
    System.exit(0);
    }
    }

    exit.addActionListener(new exitaction());
    }
    }

  2. #2
    ninjalord918 is offline Member
    Join Date
    Jul 2010
    Posts
    30
    Rep Power
    0

    Default

    ahhhh sorry, i indented the codes but it wasn't when posted. Attached is my code, please change the file type to .java if you want to run it since i couldn't attach .java file :)
    Attached Files Attached Files

  3. #3
    ninjalord918 is offline Member
    Join Date
    Jul 2010
    Posts
    30
    Rep Power
    0

    Default

    Well silly me, I found my solution. Adding JPaneScroll solved it yay!!!!

    Cheers :)

  4. #4
    ninjalord918 is offline Member
    Join Date
    Jul 2010
    Posts
    30
    Rep Power
    0

    Default

    that's JScrollPane, sorry too excited.

  5. #5
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,226
    Rep Power
    6

    Default

    ahhhh sorry, i indented the codes but it wasn't when posted
    Thats because you need to wrap the code in "code tags". Select the code and then click on the appropriate button to add the code tags.

Similar Threads

  1. Replies: 1
    Last Post: 01-08-2010, 06:19 AM
  2. Replies: 0
    Last Post: 07-07-2008, 04:47 PM
  3. React to menu action and checkbox menu
    By Java Tip in forum javax.swing
    Replies: 0
    Last Post: 06-27-2008, 07:50 PM
  4. Replies: 7
    Last Post: 05-09-2008, 07:54 AM
  5. menu inserting table in the document
    By daredavil82 in forum New To Java
    Replies: 0
    Last Post: 12-05-2007, 05:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •