Make a scrollable table

I am making this program in Java in which I sell things to those who are connected via socket. I am loading products and prices via JDBC very well, but I want to display the product with the price next to it in a scrollable table. Right now I only have this JList in which I load the product names:

Please follow the link below to understand the question.

enter image description here

What elements should I use and how to accomplish what I need?

Thanks for reading.

+3


source to share


5 answers


You need to use JTable

withJScrollPane

Updated links link links :



this referenced example and u it might help you

+4


source


I think you can accomplish this with a JTable component in swing.



+3


source


Use a JTable with a JScrollPane in it to scroll from top to bottom or left to right.

+3


source


You need a JTable in a JScrollPane.

+3


source


You need to use JTable and JScrollPane

Sample code:

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;


public class ProductTableExample {

    public static void main( String[] str ) {
        String[] colName = new String[] { "Product Name" ,"Price" };
        Object[][] products = new Object[][] { 
                { "Galleta" ,"$80" },
                { "Malta" ,"$40" },
                { "Nestea" ,"$120" },
                { "Tolta" ,"$140" } 
            };

        JTable table = new JTable( products, colName );

        JFrame frame = new JFrame( "Simple Table Example" );

        // create scroll pane for wrapping the table and add
        // it to the frame
        frame.add( new JScrollPane( table ) );
        frame.pack();
        frame.setVisible( true );       
    }

}

      

+2


source







All Articles