I want to display the JTable each time a row is added.
The code that i write below add a new row to table , then display the jtable for 2 seconds ,then add another row , then display the table. But the jtable is not displaying ,
It only display after adding all rows
Vector<Object> rowVector = null;
while(rs.next()){
rowVector = new Vector<Object>();
for(int i=1;i<=columnCount;i++){
rowVector.add(rs.getString(i));
//System.out.print(rs.getString(i));
}
System.out.println(rowVector.toString());
//data.add(rowVector);
model.addRow(rowVector);
JTable table1 = new JTable(model);
JTableHeader header1 = table1.getTableHeader();
table1.setEnabled(false);
header1.setResizingAllowed(false);
header1.setReorderingAllowed(false);
header1.setForeground(Color.white);
header1.setBackground(Color.black);
jpanedisplay.setViewportView(table1);
jpanedisplay.getViewport().setBackground(Color.white);
jpanedisplay.setBorder(BorderFactory.createLineBorder(Color.black));
Thread.sleep(3000);
}
You're creating a new JTable in each iteration, you don't need to do that. Add the model to the table before the loop. And just add rows to the model in the loop
DefaultTableModel model = new DefaultTableModel(columnNames, 0);
JTable table = new JTable(model);
table.setEnabled(false);
JTableHeader header1 = table.getTableHeader();
header1.setResizingAllowed(false);
header1.setReorderingAllowed(false);
header1.setForeground(Color.white);
header1.setBackground(Color.black);
jpanedisplay.setViewportView(table1);
jpanedisplay.getViewport().setBackground(Color.white);
jpanedisplay.setBorder(BorderFactory.createLineBorder(Color.black));
...
while(rs.next()){
Vector<Object> rowVector = new Vector<Object>();
for(int i=1;i<=columnCount;i++){
rowVector.add(rs.getString(i));
//System.out.print(rs.getString(i));
}
model.addRow(rowVector);
// DON'T CALL Thread.sleep();
}
UPDATE
If you dont want the table added until the database task is finished, just use a method
private JTable createTable(ResultSet rs) {
DefaultTableModel model = new DefaultTableModel(columnNames, 0);
JTable table = new JTable(model);
table.setEnabled(false);
JTableHeader header1 = table.getTableHeader();
header1.setResizingAllowed(false);
header1.setReorderingAllowed(false);
header1.setForeground(Color.white);
header1.setBackground(Color.black);
while(rs.next()){
Vector<Object> rowVector = new Vector<Object>();
for(int i=1;i<=columnCount;i++){
rowVector.add(rs.getString(i));
}
model.addRow(rowVector);
}
return table;
}
Then you can just add it to what ever panel
panel.add(new JScrollPane(createTable(rs));
UPDATE #2 after Op explained that they were trying to get a dynamic look the rows being added, instead of all at One time.
I used a java.swing.Timer to add the rows.
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
import javax.swing.table.DefaultTableModel;
public class TestTimerTable {
String[] cols = {"ID", "Name", "Country Code", "District", "Population"};
DefaultTableModel model = new DefaultTableModel(cols, 0);
JTable table = new JTable(model);
ResultSet rs = null;
JButton start = new JButton("Start");
Timer timer = new Timer(0, null);
public TestTimerTable() {
initDB();
JScrollPane scroll = new JScrollPane(table);
scroll.setViewportView(table);
JFrame frame = new JFrame("Test Timer Table");
frame.add(scroll);
frame.add(start, BorderLayout.SOUTH);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
timer = new Timer(200, new ActionListener() {
#Override
public void actionPerformed(ActionEvent e) {
try {
if (rs.next()) {
String s1 = rs.getString(1);
String s2 = rs.getString(2);
String s3 = rs.getString(3);
String s4 = rs.getString(4);
String s5 = rs.getString(5);
model.addRow(new Object[]{s1, s2, s3, s4, s5});
} else {
((Timer) e.getSource()).stop();
}
} catch (SQLException ex) {
ex.printStackTrace();
}
}
});
start.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent e) {
timer.start();
}
});
}
private void initDB() {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection(
"jdbc:mysql://localhost/...", "...", "...");
PreparedStatement ps = conn.prepareStatement("SELECT * FROM city");
rs = ps.executeQuery();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
#Override
public void run() {
new TestTimerTable();
}
});
}
}
Related
I don't know how to refresh data in JTable after delete or after insert from other JDialog. I tried to initiate with calling tabela(); after delete to refresh data in JTable but that don't work.
import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.JScrollPane;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import java.awt.Font;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class LekariD extends JDialog {
private final JPanel contentPanel = new JPanel();
private JTable table;
private String lekar;
private DefaultTableModel model1;
public static void main(String[] args) {
try {
LekariD dialog = new LekariD();
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
dialog.setLocationRelativeTo(null);
} catch (Exception e) {
e.printStackTrace();
}
}
Connection con = null;
public void tabela () {
Vector<Object> columnNames = new Vector<Object>();
Vector<Object> data = new Vector<Object>();
try {
String sql = "Select * from lekari";
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery( sql );
java.sql.ResultSetMetaData md = rs.getMetaData();
int columns = md.getColumnCount();
columnNames.addElement("Ime Lekara");
columnNames.addElement("LBO");
while (rs.next()) {
Vector<Object> row = new Vector<Object>(columns);
for (int i = 1; i <= columns; i++) {
row.addElement( rs.getObject(i) );
}
data.addElement( row );
}
rs.close();
stmt.close();
} catch (Exception e) {
System.out.println( e );
}
model1 = new DefaultTableModel(data, columnNames) {
#Override
public Class getColumnClass(int column)
{
for (int row = 0; row < getRowCount(); row++) {
Object o = getValueAt(row, column);
if (o != null) {
return o.getClass();
}
}
return Object.class;
}
};
}
/**
* Create the dialog.
*/
public LekariD() {
con = DatabaseConnector.dbConnector();
tabela();
setBounds(100, 100, 514, 654);
getContentPane().setLayout(new BorderLayout());
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
getContentPane().add(contentPanel, BorderLayout.CENTER);
contentPanel.setLayout(null);
JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(10, 126, 339, 478);
contentPanel.add(scrollPane);
table = new JTable(model1);
table.addMouseListener(new MouseAdapter() {
#Override
public void mouseClicked(MouseEvent arg0) {
DefaultTableModel model=(DefaultTableModel)table.getModel();
int selectedRowIndex = table.getSelectedRow();
lekar = model.getValueAt(selectedRowIndex, 0).toString();
}
});
table.setFillsViewportHeight(true);
scrollPane.setViewportView(table);
JButton btnNewButton = new JButton("Unos");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
NoviLekarD nl = new NoviLekarD();
nl.setLocationRelativeTo(null);
nl.setVisible(true);
}
});
btnNewButton.setBounds(359, 126, 129, 44);
contentPanel.add(btnNewButton);
JButton btnNewButton_1 = new JButton("Brisanje");
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
String query = "delete from lekari where ime_lekar = '"+lekar+"' ";
Statement stmt1 = con.prepareStatement(query);
stmt1.executeUpdate(query);
stmt1.close();
JOptionPane.showMessageDialog(contentPanel, "Uspešno obrisan podatak", "Brisanje !", JOptionPane.INFORMATION_MESSAGE);
} catch (Exception e2) {
System.out.println( e2 );
}
//tabela(); - tried with this but don't work
}
});
btnNewButton_1.setBounds(359, 212, 129, 44);
contentPanel.add(btnNewButton_1);
JButton btnNewButton_2 = new JButton("Izlaz");
btnNewButton_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
con.close();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
dispose();
}
});
btnNewButton_2.setBounds(359, 560, 129, 44);
contentPanel.add(btnNewButton_2);
JLabel lblSpisakLekara = new JLabel("Spisak lekara");
lblSpisakLekara.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 18));
lblSpisakLekara.setBounds(10, 42, 139, 38);
contentPanel.add(lblSpisakLekara);
}
}
Let's take a look at what's happening:
When you call tabela() you query the database and create a new DefaultTableModel in model1.
During construction in LekariD() you create a new instance of JTable and provide it with model1.
On change you update the database and call tabela() again. This creates a new DefaultTableModel in model1. Your table still holds the previous DefaultTableModel and queries it whenever you require some data to be drawn.
So, what you have to do after tabela() is to provide your table with the new table model:
table.setModel(model1);
This let's your table know about the new data and makes it recalculate columns, redraw itself, etc.
I've populated JTable from database. But the table is not appearing. I can not figure out the problem with the code. I can not understand whether the problem is with layout or the code block retrieving data from database. Also I am not getting any Exception message. I've added frame.getContentPane().add(scroll, BorderLayout.CENTER); in the code, still can not the table. Please see the attached image what I am getting.
import java.awt.EventQueue;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import java.awt.BorderLayout;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import controller.DB_con;
public class Jtable {
private JFrame frame;
private JTable table;
String[] columnNames = {"ID", "name", "username", "contact", "GENDER"};
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Jtable window = new Jtable();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
System.out.println(e.toString());
}
}
});
}
/**
* Create the application.
*/
public Jtable() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(new BorderLayout(0, 0));
table = new JTable();
frame.getContentPane().add(table, BorderLayout.CENTER);
DefaultTableModel model = new DefaultTableModel();
model.setColumnIdentifiers(columnNames);
table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
table.setFillsViewportHeight(true);
JScrollPane scroll = new JScrollPane(table);
frame.getContentPane().add(scroll, BorderLayout.CENTER);
scroll.setHorizontalScrollBarPolicy(
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scroll.setVerticalScrollBarPolicy(
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
try
{
Connection sqlCon = DB_con.getSQLConnection();
PreparedStatement ps = sqlCon.prepareStatement("select id,name,username,contact,gender from temp_tbl");
int i = 0;
ResultSet rs = ps.executeQuery();
while(rs.next())
{
String id = rs.getString("id");
String name = rs.getString("name");
String username = rs.getString("username");
String contact = rs.getString("contact");
String gender = rs.getString("gender");
model.addRow(new Object[]{id, name, username, contact, gender});
i++;
}
}
catch(Exception ex)
{
System.out.println(ex.toString());
}
}
}
You add the JTable to the frame, you then add it to the JScrollPane but never add the JScrollPane to the anything ...
A component can only reside within a single container, so when you do JScrollPane scroll = new JScrollPane(table);, you are removing the JTable from the frame.
Add frame.getContentPane().add(scroll, BorderLayout.CENTER); after you've created the JScrollPane
You also never apply the TableModel to the JTable
table.setModel(model);
frame.getContentPane().add(scroll, BorderLayout.CENTER);
My GUI application is Connecting to the DB and I have managed to add a product from the DB to my JTable on the GUI. When I click a second button it overwrites the first. I do not want this as it is an order till system and I want whatever I click to appear on the table as it is clicked. Is there any way to append onto the table rather than overwriting the values every time. Here is my code.
americanoSmall.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try {
String query = "select ProductName, Price from product where ProductID = 24";
java.sql.PreparedStatement pst = connection.prepareStatement(query);
ResultSet rs = pst.executeQuery();
table.setModel(DbUtils.resultSetToTableModel(rs));
} catch (Exception e1)
{
e1.printStackTrace();
}
}
});
Don't change the table model whenever the model changes. Instead, use the addRow method of the TableModel. Here's a minimal, complete and verifiable example.
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
public class Test {
public static void main(String[] args) {
JFrame frame = new JFrame("Test");
Container cont = frame.getContentPane();
cont.setLayout(new BorderLayout());
DefaultTableModel dtm = new DefaultTableModel(new Object[]{"Column 1","Column 2"}, 0);
JTable table = new JTable(dtm);
JScrollPane scroll = new JScrollPane(table);
cont.add(scroll, BorderLayout.CENTER);
dtm.addRow(new Object[]{"Value 1", "Value 2"});
JButton add = new JButton("Add");
cont.add(add, BorderLayout.NORTH);
add.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent e) {
dtm.addRow(new Object[]{"Another value", "Another value"});
}
});
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
I have a textbox which sent something to database and jtable list the values from database. But when i add something to database. Jtable dont show it in same time. when i close the program and debug again, it shows that time. I want Jtabel to show textbox value when i click the save button. How can i create a dynamic jtable?
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
public class Topic extends JFrame {
private static final long serialVersionUID = 1L;
JFrame frmTopic;
JPanel pnl, pnl_generaltopic;
static JTextField txt_topic;
JLabel lbl_topicNme, lbl_topicpage;
JButton btn_close, btn_update, btn_save;
public static Connection con = null;
public static ResultSet rs = null;
public static Statement st = null;
static Vector<Vector<String>> data = new Vector<Vector<String>>();
private JScrollPane scrollPane;
private static JTable table;
public Topic() {
pnl_generaltopic = new JPanel();
pnl_generaltopic.setBackground(Color.lightGray);
pnl_generaltopic.setLayout(null);
frmTopic = new JFrame("Topic");
frmTopic.addWindowListener(new WindowAdapter() {
#Override
public void windowOpened(WindowEvent arg0) {
con = Dbconnect.conect();
}
});
frmTopic.setTitle("E-TEST");
frmTopic.setBounds(100, 100, 500, 500);
frmTopic.setVisible(true);
frmTopic.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frmTopic.getContentPane().setLayout(new BorderLayout(0, 0));
frmTopic.getContentPane().add(pnl_generaltopic);
topicPanel();
topicTable();
}
public void topicPanel() {
JPanel panel_addingNewTopic = new JPanel();
panel_addingNewTopic.setBounds(10, 0, 464, 203);
pnl_generaltopic.add(panel_addingNewTopic);
panel_addingNewTopic.setLayout(null);
btn_save = new JButton("Save");
btn_save.setBounds(65, 166, 67, 23);
panel_addingNewTopic.add(btn_save);
btn_update = new JButton("Update");
btn_update.setBounds(142, 162, 90, 30);
panel_addingNewTopic.add(btn_update);
btn_close = new JButton("Close");
btn_close.setBounds(240, 162, 90, 30);
panel_addingNewTopic.add(btn_close);
txt_topic = new JTextField();
txt_topic.setBounds(65, 59, 270, 71);
panel_addingNewTopic.add(txt_topic);
lbl_topicNme = new JLabel("Topic Name");
lbl_topicNme.setBounds(10, 65, 150, 59);
panel_addingNewTopic.add(lbl_topicNme);
lbl_topicpage = new JLabel("Topic Page");
lbl_topicpage.setBounds(10, 11, 300, 20);
panel_addingNewTopic.add(lbl_topicpage);
lbl_topicpage.setFont(new Font("arial", Font.BOLD, 15));
btn_close.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
frmTopic.dispose();
}
}
);
btn_save.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
st = con.createStatement();
String sorgu = "insert into topic " + "(topicname)"
+ "VALUES ('" + txt_topic.getText() + "')";
st.executeUpdate(sorgu);
JOptionPane.showMessageDialog(Topic.this, "Topic was added");
} catch (Exception s) {
System.out.print(s.getMessage());
}
}
}
);
}
public void topicTable() {
scrollPane = new JScrollPane();
scrollPane.setBounds(10, 226, 464, 190);
pnl_generaltopic.add(scrollPane);
Vector<String> headers = new Vector<String>();
headers.add("Topic Name");
getData();
//this is the model which contain actual body of JTable
DefaultTableModel model = new DefaultTableModel(data, headers);
table = new JTable(model);
scrollPane.setColumnHeaderView(table);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
//table=new JTable(model);
//table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
header_size();
//JScrollPane scroll = new JScrollPane(table);
scrollPane.setHorizontalScrollBarPolicy(
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scrollPane.setVerticalScrollBarPolicy(
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
pack();
setResizable(false);
setVisible(true);
}
/**
* Setting the particular Column Size in JTable
*/
public static void header_size() {
TableColumn column = table.getColumnModel().getColumn(0);
column.setPreferredWidth(100);
column = table.getColumnModel().getColumn(0);
column.setPreferredWidth(350);
}
/**
* Fetching Data From MySql Database
* and storing in a Vector of a Vector
* to Display in JTable
*/
private static void getData() {
// Enter Your MySQL Database Table name in below Select Query.
String str = "select * from topics";
Connection con;
ResultSet rs;
Statement st;
try {
con = DriverManager.getConnection("jdbc:mysql://" + "localhost:3306/database", "root", "1234");
st = con.createStatement();
rs = st.executeQuery(str);
while (rs.next()) {
Vector<String> d = new Vector<String>();
d.add(rs.getString("topicname"));
d.add("\n\n\n\n\n\n\n");
data.add(d);
}
} catch (SQLException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
Topic topic = new Topic();
topic.setVisible(false);
}
}
You can use the addRow(...) method of the DefaultTableModel to dynamically add a row of data in the model.
So if the update to your database is successful, then you would invoke the addRow() method.
Also, you should use a PreparedStatement when using SQL. It will make creating the SQL easier since you don't need to worry about the delimiters. Simple example to give you an idea:
String sql = "INSERT INTO Page (Name, Title) VALUES (?, ?)";
PreparedStatement stmt = connection.prepareStatement(sql);
stmt.setString( 1, "Name1" );
stmt.setString( 2, textField.getText() );
stmt.executeUpdate();
I am trying to populate a table from a text file using vectors. Should I be creating a new vector for each row? Is there anything else that appears wrong with my code? I'm not quite sure what to do from here.
public class myJTable {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Vector<String> v = new Vector<String>();
Vector<Vector<String>> rowData = new Vector<Vector<String>>();
//String splitting
try {
FileReader fReader = new FileReader("lakedata.txt");
BufferedReader inFile = new BufferedReader(fReader);
String input;
String[] temp;
while((input=inFile.readLine())!=null) {
temp = input.split(",",3);
for(int i=0; i<temp.length; i++) {
v.addElement(temp[i]);
System.out.println(temp[i]);
}
System.out.println(v);
rowData.addElement(v);
}
inFile.close();
}
catch(Exception e) {
System.out.println("ERROR");
}
Vector<String> columnNames = new Vector<String>();
columnNames.addElement("Depth");
columnNames.addElement("Temperature");
columnNames.addElement("D.O.");
JTable table = new JTable(rowData, columnNames);
JScrollPane scrollPane = new JScrollPane(table);
frame.add(scrollPane, BorderLayout.CENTER);
frame.setSize(500,300);
frame.setVisible(true);
}
}
Instead of using Vector, you can create a DefaultTableModel then set it as the model of the table, then invoke its addRow method to directly put the read line result to the table. The table will automatically update itself when data to a table is added.
I took the liberty to revise your code into a cleaner one.
import java.awt.BorderLayout;
import java.io.BufferedReader;
import java.io.FileReader;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.table.DefaultTableModel;
public class TablePopulation {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
#Override public void run() {
JTable table = new JTable();
JScrollPane scrollPane = new JScrollPane(table);
/* Set the table data to null first since
* we will fetch data from file line by line
* -------------------------------------- */
DefaultTableModel model = new DefaultTableModel(null, new String[]{"Depth","Temperature","D.O."});
table.setModel(model);
/* String splitting
* ---------------- */
try {
FileReader fReader = new FileReader("file.txt");
BufferedReader inFile = new BufferedReader(fReader);
String input = inFile.readLine();
while(input !=null) {
String[] temp = input.split(",");
model.addRow(temp);
input = inFile.readLine();
}
inFile.close();
}catch(Exception e) {
e.printStackTrace();
}
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(scrollPane, BorderLayout.CENTER);
frame.setSize(500,300);
frame.setVisible(true);
}
});
}
}
Also, atleast put e.printStackTrace() (since you're not using any logging framework) in the catch block to see the stack trace of what's going on in case some error has been caught.