Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: add table to button

  1. #1
    Junior Member DeniLeet's Avatar
    Join Date
    May 2013
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default add table to button

    Hello, I want to add a table to button MouseListener does not work because i cant call class. Any ideas what should i do ?

    Table:
    public static void Table(){

    JTable jt;
    String[]columns = {"Kind","Weight","Location","Date","Bait"};
    String[][]data = {{"Carp","2kg","Levkuška","29.5.2013","HotDeamon"} ,{"Carp","3kg","Levkuška","29.5.2013","HotDeamon"} ,{"Carp","4kg","Levkuška","29.5.2013","HotDeamon"} };

    jt= new JTable(data,columns);
    jt.setPreferredScrollableViewportSize(new Dimension(640,100));
    jt.setFillsViewportHeight(true);
    JScrollPane jsp = new JScrollPane();
    add(jsp);
    }

    MouseListener:

    package fishman.denileet;

    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;

    import javax.swing.JButton;

    public class CustomTable implements MouseListener {

    private JButton button1;

    public CustomTable(JButton button1) {
    this.button1= button1;
    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,972
    My Mood
    Hungover
    Thanks
    133
    Thanked 555 Times in 476 Posts

    Default Re: add table to button

    I'm really not sure what you want to do. You want to add the JTable to the JButton? Or you want to add the JButton's MouseListener to the JButton as well? Why is there a JButton in your MouseListener? That code is confusing to say the least...
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member DeniLeet's Avatar
    Join Date
    May 2013
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: add table to button

    Quote Originally Posted by KevinWorkman View Post
    I'm really not sure what you want to do. You want to add the JTable to the JButton? Or you want to add the JButton's MouseListener to the JButton as well? Why is there a JButton in your MouseListener? That code is confusing to say the least...
    So I have added som buttons to my frame . and i want to attach table to one of the buttons.So after click on, it calls the table. This is my plane im just not sure if it is possible.The mouse listener has own class

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,972
    My Mood
    Hungover
    Thanks
    133
    Thanked 555 Times in 476 Posts

    Default Re: add table to button

    I think you need to clear up exactly what you want to happen, and take them one small step at a time.

    You want to add JButtons to a JFrame, right? Have you done that? If not, do this before thinking about the rest of the problem. Recommended reading: How to Use Buttons, Check Boxes, and Radio Buttons (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)

    You want to do something when a JButton is clicked, right? Start simple and just display a message when a button is clicked. Recommended reading: http://docs.oracle.com/javase/tutori...nlistener.html

    What do you want to happen to the JTable when the JButton is clicked? Consult the API for functions that might do what you want.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. The Following User Says Thank You to KevinWorkman For This Useful Post:

    DeniLeet (June 4th, 2013)

  6. #5
    Junior Member DeniLeet's Avatar
    Join Date
    May 2013
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: add table to button

    Hm.I have already done the first and second step. It would be nice if Table appears after clicking on button

  7. #6
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,972
    My Mood
    Hungover
    Thanks
    133
    Thanked 555 Times in 476 Posts

    Default Re: add table to button

    Sounds like you want to set the visibility of the table, right? Is there a method in the API for the JTable class that does something like that? Java Platform SE 7
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  8. #7
    Junior Member DeniLeet's Avatar
    Join Date
    May 2013
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: add table to button

    I'll try find something.When I'm doing it in blank project it works i forgot to say. It just dont want to work when i put it into my main project

Similar Threads

  1. Trying to add a button to my Title Screen...
    By Jnk1296 in forum AWT / Java Swing
    Replies: 5
    Last Post: January 25th, 2013, 10:51 AM
  2. I can not redeem the action of a button within a table.
    By pezinho45 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 22nd, 2012, 07:35 AM
  3. Adding add/remove button to add/remove tab
    By JMtrasfiero in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 27th, 2012, 11:24 AM
  4. Trying to add a close button
    By coyboss in forum Java Theory & Questions
    Replies: 5
    Last Post: February 12th, 2011, 02:28 PM
  5. Adding Marathi words to MySQL table
    By vaishali in forum JavaServer Pages: JSP & JSTL
    Replies: 3
    Last Post: July 8th, 2009, 06:43 AM