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.
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 to share
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 to share