I am currently working on a gui project which is managing a sql database. I am currently adding,deleting logs and showing tables existing in mysql. The problem is my add and delete buttons on my panel are supposed to repaint/refresh the table on that panel as a record is added or deleted however while testing I discovered that repaint method doesn't refresh the table after the first use of the button. What can cause this problem? Thanks in advance..
public JTabbedPane addComponentToPane() {
//Container pane = new Container();
JTabbedPane tabbedPane = new JTabbedPane();
JPanel card1 = new JPanel();
JPanel card2 = new JPanel();
JPanel card3 = new JPanel();
JPanel card4 = new JPanel();
JPanel card5 = new JPanel();
JPanel card6 = new JPanel();
JPanel card7 = new JPanel();
JPanel card8 = new JPanel();
card1.setLayout(new BorderLayout());
card2.setLayout(new BorderLayout());
card3.setLayout(new BorderLayout());
card4.setLayout(new BorderLayout());
card5.setLayout(new BorderLayout());
card6.setLayout(new BorderLayout());
card7.setLayout(new BorderLayout());
card8.setLayout(new BorderLayout());
JScrollPane actor = new JScrollPane(createTables("actor"));
card1.add(actor, BorderLayout.CENTER);
card3.add(createTables("address"), BorderLayout.CENTER);
card4.add(createTables("category"), BorderLayout.CENTER);
card5.add(createTables("city"), BorderLayout.CENTER);
card6.add(createTables("country"), BorderLayout.CENTER);
card7.add(createTables("customer"), BorderLayout.CENTER);
card8.add(createTables("film"), BorderLayout.CENTER);
JButton button = new JButton("Yeni Kayıt");
button.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent e) {
addRecord("actor");
card1.remove(actor);
card1.add(createTables("actor"), BorderLayout.CENTER);
card1.validate();
card1.repaint();
}
});
JButton delButton = new JButton("Kayıt sil");
delButton.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent e) {
delRecord("actor");
card1.remove(actor);
card1.add(createTables("actor"), BorderLayout.CENTER);
card1.validate();
card1.repaint();
}
});``
card1.add(button, BorderLayout.SOUTH);
card1.add(delButton, BorderLayout.EAST);
tabbedPane.addTab("Şirketler", null, card1, "şirket tanımları");
tabbedPane.addTab("Sorumlular", card2);
tabbedPane.addTab("Varlık Grupları", card3);
tabbedPane.addTab("Bilgi Varlıkları", card4);
tabbedPane.addTab("Varlık Değerleri", card5);
tabbedPane.addTab("Açıklıklar", card6);
tabbedPane.addTab("Tehditler", card7);
tabbedPane.addTab("Ek-A", card8);
//pane.add(tabbedPane, BorderLayout.CENTER);
return tabbedPane;
}
Create tables method creating a Jtable from sql table.
private JScrollPane createTables(String tablename) {
Connection con = null;
Statement statement = null;
ResultSet result = null;
String query;
JScrollPane jsp = null;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/sakila", "root", "root");
statement = con.createStatement();
query = "select * from " + tablename;
result = statement.executeQuery(query);
ResultSetMetaData rsmt = result.getMetaData();
int columnCount = rsmt.getColumnCount();
Vector column = new Vector(columnCount);
for (int i = 1; i <= columnCount; i++) {
column.add(rsmt.getColumnName(i));
}
Vector data = new Vector();
Vector row = new Vector();
while (result.next()) {
row = new Vector(columnCount);
for (int i = 1; i <= columnCount; i++) {
row.add(result.getString(i));
}
data.add(row);
}
defTableModel = new DefaultTableModel(data, column);
table = new JTable(defTableModel) {
#Override
public boolean isCellEditable(int row, int column) {
return false;
}
;
};
//table.setAutoCreateRowSorter(true);
TableRowFilterSupport.forTable(table).searchable(true).apply();
table.setRowSelectionAllowed(true);
jsp = new JScrollPane(table);
}
catch (Exception e) {
e.printStackTrace();
// JOptionPane.showMessageDialog(null, "ERROR");
}
finally {
try {
statement.close();
result.close();
con.close();
}
catch (Exception e) {
//JOptionPane.showMessageDialog(null, "ERROR CLOSE");
}
}
return jsp;
}
I could see couple of inconsistencies in the code:
The actor variable is not being set to the added component in the action listener.
First time you are adding new JScrollPane(createTables("actor")) and then onwards you only add createTables("actor").
The (1) might be causing the problem.
I think the problem is the reference to the actor:
card1.remove(actor);
card1.add(createTables("actor"), BorderLayout.CENTER);
Here, the variable actor is not more referenced in card1. To not lose this reference you should do something like this, in both actionPerformed methods:
card1.remove(actor);
actor = new JScrollPane(createTables("actor"));
card1.add(actor, BorderLayout.CENTER);
Related
I have a little problem in this code. I want to display a JTable with Column Headers but the problem is that the column's titles are not being displayed, as the Screenshot shows below:
private static final String DB_DRIVER = "oracle.jdbc.driver.OracleDriver";
private static final String DB_CONNECTION = "jdbc:oracle:thin:#localhost:1521:DB";
private static final String DB_USER = "*******";
private static final String DB_PASSWORD = "********";
Connection conn = null;
Statement stmt = null;
static Vector<Vector<String>> dataJ, dataC, data;
Vector<String> columnJ,
public void getCleubJoueurData() {
data = new Vector<Vector<String>>();
colum = new Vector<String>();
colum.add("nom");
colum.add("nom_cleub");
colum.add("numero_maillot");
colum.add("nationalite");
String query = "SELECT joueur.NOM,CLEUB.NOM_CLEUB," +
"JOUEUR_CLEUB.NUMERO_MAILLOT, joueur.NATIONALITE " +
"FROM joueur JOIN JOUEUR_CLEUB ON joueur.ID_J=" +
"JOUEUR_CLEUB.ID_J JOIN CLEUB ON JOUEUR_CLEUB.ID_C=CLEUB.ID_C";
try {
try {
Class.forName(DB_DRIVER);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
conn = DriverManager.getConnection(DB_CONNECTION, DB_USER, DB_PASSWORD);
stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
Vector<String> vstring = new Vector<String>();
vstring.add(rs.getString("nom"));
vstring.add(rs.getString("nom_cleub"));
vstring.add(rs.getString("numero_maillot"));
vstring.add(rs.getString("nationalite"));
data.add(vstring);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (stmt != null) {
try {
stmt.close();
} catch (SQLException ex) {
}
}
}
}
public App() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 882, 477);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
tabbedPane.setBackground(Color.WHITE);
tabbedPane.setBounds(40, 43, 812, 390);
contentPane.add(tabbedPane);
JPanel panel = new JPanel();
tabbedPane.addTab("joueurs", null, panel, null);
panel.setLayout(null);
getJoueurData();
DefaultTableModel mode = new DefaultTableModel(data, column);
table = new JTable(model);
table.setToolTipText("");
table.setBounds(0, 94, 819, 269);
panel.add(table);
}
Don't use null layouts. (And don't set the bounds)
Wrap your table in a JScrollPane. The JScrollPane will show the headers. If you don't want to use a JScrollPane, then you can get the JTableHeader of the table and add it separately
Former: (with JScrollPane)
JPanel container = new JPanel(); // default FlowLayout
JScrollPane scrollPane = new JScrollPane(table);
//container.add(table); // don't add the table, just the JScrollPane
container.add(scrollPane);
Latter: (without JScrollPane)
JPanel container = new JPanel(new BorderLayout());
container.add(table, BorderLayout.CENTER);
container.add(table.getTableHeader(), BorderLayout.PAGE_START);
The JTable documentation states that you'd typically want to use JTable in conjunction with a JScrollPane. If not:
JTables are typically placed inside of a JScrollPane. [...] Note that if you wish to
use a JTable in a standalone view (outside of a JScrollPane) and want
the header displayed, you can get it using getTableHeader() and
display it separately.
I'd recommend wrapping in a JScrollPane myself:
...
JScrollPane scrollPane = new JScrollPane(table);
panel.add(scrollPane);
...
So I have this application with a JTable in it. The JTable is inside of a JScrollPane and JScrollPane is painted on a JFrame.
Now in my application I open a new windows to add a new row to that table and after I click a button to save the changes, the new window closes.
Now I have tried adding these lines after the new window is closed:
askTableInfo(); //a method to save the info in database to table and then save the table to variable 'table'
table.repaint();
scrollPane.repaint();
And of course repaint(); by it self. But it still does not seem to update my table in the JFrame.
What could be the issue here?
public class AppWindow extends JFrame implements ActionListener {
String user = "";
JLabel greetText = new JLabel();
JPanel panel = new JPanel();
JPanel panel2 = new JPanel(new GridLayout(1, 3));
JScrollPane scrollPane;
JTable tabel;
JButton newBook = new JButton("Add a book");
JButton deleteBook = new JButton("Remove a book");
JButton changeBook = new JButton("Change a book");
int ID;
public AppWindow(String user, int ID) {
this.ID = ID;
this.user = user;
setSize(500, 500);
setTitle("Books");
setLayout(new BorderLayout());
greetText.setText("Hi "+user+" here are your books:");
add(greetText, BorderLayout.NORTH);
askData();
panel.add(scrollPane);
add(panel, BorderLayout.CENTER);
panel2.add(newBook);
panel2.add(deleteBook);
panel2.add(changeBook);
add(paneel2, BorderLayout.SOUTH);
newBook.addActionListener(this);
setVisible(true);
}
private void askData() {
DataAsker asker = null;
try {
asker = new AndmeKysija(ID);
} catch (SQLException e) {
e.printStackTrace();
}
table = asker.giveTable();
scrollPane = new JScrollPane(tabel);
}
public static void main(String[] args){
AppWindow window = new AppWindow("Name", 2);
}
#Override
public void actionPerformed(ActionEvent e) {
if(e.getSource() == newBook){
new BookAdded(ID);
panel.revalidate();
panel.add(scrollPane);
panel.repaint();
repaint();
}
}
}
Not the best method, but it will get you across the line...
public AppWindow(String user, int ID) {
this.ID = ID;
this.user = user;
setSize(500, 500);
setTitle("Books");
setLayout(new BorderLayout());
greetText.setText("Hi "+user+" here are your books:");
add(greetText, BorderLayout.NORTH);
JTable table = askData();
scrollPane.setViewportView(table);
panel.add(scrollPane);
add(panel, BorderLayout.CENTER);
panel2.add(newBook);
panel2.add(deleteBook);
panel2.add(changeBook);
add(paneel2, BorderLayout.SOUTH);
newBook.addActionListener(this);
setVisible(true);
}
private JTable askData() {
DataAsker asker = null;
try {
asker = new AndmeKysija(ID);
} catch (SQLException e) {
e.printStackTrace();
}
return asker.giveTable();
}
public static void main(String[] args){
AppWindow window = new AppWindow("Name", 2);
}
#Override
public void actionPerformed(ActionEvent e) {
if(e.getSource() == newBook){
new BookAdded(ID);
JTable table = askData();
scrollPane.setViewportView(table);
}
}
What you should be doing is creating a new TableModel from the results of AndmeKysija, AndmeKysija should have idea or concept of the UI. You would then simply need to use JTable#setModel to update the view...
Swing uses a varient of the Model-View-Controller paradigm
The scrollPane table isn't refreshing for every time I selected something from the combo. Initially it has data but after I selected something, the data is removed successfully but new data isn't populating in
public void ConsultFrame(String id, String name, String ic){
GenerateMed("dp-000"); // to begin the scrollpane filled with Fever's medicine
JButton proc = new JButton("Proceed");
JButton addmed = new JButton(">>");
selected = new JTable(data, columnNames){
#Override
public boolean isCellEditable(int row,int column){
switch(column){
case 0:
return false;
case 1:
return false;
default: return true;
}
}};
selectedPane = new JScrollPane(selected);
//Dispensary's category combobox related
disp = dbDisp.getDispensary();
final JComboBox cBox = new JComboBox();
for(int count=0; count<disp.size(); count++)
cBox.addItem(disp.get(count).getDSP_desc());
cBox.addItemListener(new ItemListener() {
#Override
public void itemStateChanged(ItemEvent event) {
for(int count=0; count<disp.size(); count++){
if(cBox.getSelectedItem().equals(disp.get(count).getDSP_desc())){
System.out.println(disp.get(count).getDSP_ID());
GenerateMed(disp.get(count).getDSP_ID());
break;
}
}
}
});
JTextArea tArea = new JTextArea(5, 30);
JScrollPane desc = new JScrollPane(tArea);
tArea.setLineWrap(true);
desc.setVerticalScrollBarPolicy ( ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS );
JPanel info = new JPanel();
info.setLayout(new FlowLayout(FlowLayout.LEFT));
info.add(new JLabel("<html>Patient's ID : " + id + "<br>Patient's Name: " + name + "<br>Patient's IC : " + ic + "<br><br>Medical Description : </html>"));
info.add(desc);
JPanel medSelect = new JPanel();
medSelect.setLayout(new GridLayout(1,2));
medSelect.add(scrollPane);
medSelect.add(selectedPane);
JPanel medic = new JPanel();
medic.setLayout(new BorderLayout());
medic.add(cBox, BorderLayout.NORTH);
medic.add(medSelect, BorderLayout.CENTER);
medic.add(proc, BorderLayout.SOUTH);
JPanel all = new JPanel();
String timeStamp = new SimpleDateFormat("yyyy/MM/dd HH:mm").format(Calendar.getInstance().getTime());
title = BorderFactory.createTitledBorder(timeStamp);
title.setTitleJustification(TitledBorder.RIGHT);
all.setBorder(title);
all.setLayout(new GridLayout(2,1));
all.add(info);
all.add(medic);
JFrame consult = new JFrame();
consult.setTitle(name + "'s consultation");
consult.setResizable(false);
consult.setVisible(true);
consult.setSize(500, 460);
consult.setLocationRelativeTo(null);
consult.add(all);
}
This is where my Combobox's is heading as soon as something is selected and I've tried repaint & revalidate
public void GenerateMed(String dps_id){
if (tModel != null) {
for (int i = tModel.getRowCount() - 1; i > -1; i--)
tModel.removeRow(i);
}
tModel = dbMed.getDPSMedicine(dps_id);
tModel.fireTableDataChanged();
table = new JTable(tModel){
#Override
public boolean isCellEditable(int row,int column){
return false;
}};
table.setShowGrid(false);
table.setShowHorizontalLines(false);
table.setShowVerticalLines(false);
//Table customization
table.getTableHeader().setReorderingAllowed(false);
table.setRowSelectionAllowed(true);
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.changeSelection(0, 0, false, false);
scrollPane = new JScrollPane(table);
scrollPane.repaint();
scrollPane.revalidate();
}
scrollPane = new JScrollPane(table);
The above line of code creates a new scrollPane, but doesn't add the scrollPane to the frame.
However, there is no need to even create a new JTable or a new JScrollPane. Get rid of all the code.
Instead you just change the model of your JTable by using:
table.setModel( dbMed.getDPSMedicine(dps_id) );
So basically your method becomes one line of code.
Also, use proper method names. Method names should NOT start with an upper case character.
i) My Table contains no of columns and a jcheckbox i the last column.
ii) I am using a combobox to select certain value.
iii) based on the value of combo box the jbutton loads the data into the table.
iv) when i reload the data into the table, the new data gets displayed in jtable.
v) The problem is that, When I press the Jcheckbox, the old data is getting displayed in jtable.
code is as below:
public class aap2 extends JFrame {
#SuppressWarnings({ "unchecked", "rawtypes" })
static JComboBox year = new JComboBox(new Object[]
{"2012-13", "2013-14", "2014-15", "2015-16","2016-17","2017-
18","2018-19"});
#SuppressWarnings({ "unchecked", "rawtypes" })
static JComboBox division = new JComboBox(new Object[]
{"Name", "address","profession","others"});
JComboBox schemetype = new JComboBox(new Object[]
{});
JButton showschemes = new JButton("Show Schemes");
static ResultSet rs;
Connection con;
Statement st;
static JPanel panel = new JPanel();
static JPanel panel1 = new JPanel();
static JPanel panel2= new JPanel();
static JPanel panel3= new JPanel();
static JPanel panel4= new JPanel();
static JPanel panel5= new JPanel();
UIManager ui= new UIManager();
static int columns;
static int sel[];
JTable table;
DefaultTableModel dtm;
public aap2(){
division.setMaximumRowCount(5);
year.setMaximumRowCount(5);
year.setForeground(Color.blue);
year.setBackground(Color.white);
year.setSelectedItem("2009-10");
setBounds(00,40,1020,700);
Color c= new Color(160,200,100);
getContentPane().setBackground(c);
Color c3= new Color(0,50,50,2);
panel1.setBackground(c3);
panel2.setBackground(c3);
panel.setBackground(c);
panel.setBorder(new TitledBorder(new LineBorder(Color.white,1),""));
panel.setLayout(new GridBagLayout());
GridBagConstraints gc= new GridBagConstraints();
panel1.setLayout( new GridBagLayout());
GridBagConstraints gc1 = new GridBagConstraints();
gc1.gridx=0;
gc1.gridy=0;
panel1.add( new JLabel("Financial Year"),gc1);
gc1.insets= new Insets(1,10,1,10);
gc1.gridx=1;
gc1.gridy=0;
panel1.add(year,gc1);
gc1.gridx=4;
gc1.gridy=0;
panel1.add( new JLabel("Division"),gc1);
gc1.gridx=5;
gc1.gridy=0;
panel1.add(division,gc1);
gc.gridx=0;
gc.gridy=0;
panel.add(panel1,gc);
JPanel p2= new JPanel();
gc.gridx=0;
gc.gridy=4;
p2.setBackground(c3);
panel.add(p2,gc);
panel3.setLayout( new GridBagLayout());
GridBagConstraints gc3 = new GridBagConstraints();
gc3.insets= new Insets(30,10,1,10);
gc3.gridx=0;
gc3.gridy=2;
panel3.add(showschemes,gc3);
showschemes.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e){
showschemsActionPerformed(e);
}
});
gc.gridx=0;
gc.gridy=5;
panel3.setBackground(c3);
panel.add(panel3,gc);
add(panel, BorderLayout.NORTH);
setUndecorated(true);
getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public void showschemsActionPerformed(ActionEvent e) {
showtable();
}
public void showtable() {
final Vector<String> columnNames = new Vector<String>();
final Vector<Vector<Object>> data = new Vector<Vector<Object>>();
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Driver loaded");
// Establish a connection
con= DriverManager.getConnection
("jdbc:odbc:ysr");
System.out.println("Database connecteddddd");
// Create a statement
st = con.createStatement();
ResultSet rs = st.executeQuery("SELECT * FROM ysr2011 where=
'"+division.getSelectedItem()+"' ");
ResultSetMetaData md = rs.getMetaData();
columns = md.getColumnCount();
System.out.println("col" +(columns+1));
for (int i = 1; i <= columns; i++) {
columnNames.addElement( md.getColumnName(i) );
}
columnNames.addElement("Save");
while (rs.next()) {
Vector<Object> row = new Vector<Object>(columns);
for (int i = 1; i <= columns; i++) {
row.addElement( rs.getObject(i) );
}
row.addElement(new Boolean(false));
data.addElement( row );
}
rs.close();
con.close();
st.close();
}
catch(Exception e1){}
dtm = new DefaultTableModel(data, columnNames) {
public Class getColumnClass(int col) {
if(col==columns){
return Boolean.class;
}else{
return String.class;
}
}
public boolean isCellEditable(int rowIndex, int colIndex) {
return (colIndex == columns);
}
};
dtm.fireTableDataChanged();
table= new JTable(dtm); ;
table.setFont(new Font(" Arial",Font.PLAIN,12));
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.setAutoCreateRowSorter(true);
JTableHeader header = table.getTableHeader();
header.setBackground(Color.yellow);
table.setRowSelectionAllowed(false);
header.setFont(new Font(" Arial",Font.BOLD,12));
JScrollPane scrollPane = new JScrollPane(table);
JButton button= new JButton("Save");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
for (int row = 0; row < table.getRowCount(); row++) {
Boolean b = ((Boolean) table.getValueAt(row, columns));
if (b.booleanValue()) {
System.out.print("row " + row + " is " + b + ": ");
for (int col = 0; col < table.getColumnCount(); col++) {
System.out.print(table.getValueAt(row, col) + " ");
}
System.out.println();
}
}
}
});
JPanel buttonpanel= new JPanel();
buttonpanel.add(button);
add(scrollPane,BorderLayout.CENTER);
add(buttonpanel,BorderLayout.SOUTH);
Color c1= new Color(160,200,100);
table.setBackground(c1);
buttonpanel.setBackground(c1);
setBackground(c1);
setVisible(true);
}
public static void main(String args[]){
new aap2();
}
}
When you want to change the data in your table, try to create a new DefaultTableModel object (or any other object that implements the TableModel interface), and call table.setModel(yourNewModel);
Can someone take a look at this part of my code and tell me why it won't return the objects inside the JPanel? It definitely goes inside the loop since I tried printing statements inside. Also this JPanel object is being put inside a TabbedPane just for clarification. Let me know if I need to explain in more detail or show more code to find a solution. Thanks.
JPanel createTipTailoringPanel(TipCalcModel model)
{
JPanel content = new JPanel();
int size = model.getNumOfPeople();
content.removeAll();
content.updateUI();
content.setLayout(new GridLayout(0,4));
JTextField text[] = new JTextField[size];
JSlider slider[] = new JSlider[size];
JLabel label[] = new JLabel[size];
JLabel cash[] = new JLabel[size];
if(size == 0)
{
return content;
}
else
{
for(int i=0; i<size; i++)
{
text[i] = new JTextField();
slider[i] = new JSlider();
label[i] = new JLabel("$");
cash[i] = new JLabel();
content.add(text[i]);
content.add(slider[i]);
content.add(label[i]);
content.add(cash[i]);
}
return content;
}
}
Here is my calling method and the actionlistener that I use to pass in the numberofpeople:
TipCalcView(TipCalcModel model)
{
setTitle("Tip Calculator");
JTabbedPane tabbedPane = new JTabbedPane();
getContentPane().add(tabbedPane);
tabbedPane.addTab("Main Menu", createMainPanel());
tabbedPane.setSelectedIndex(0);
tabbedPane.addTab("Tip Tailoring", createTipTailoringPanel(model));
tabbedPane.addTab("Config Panel", createConfigPanel());
}
class GuestsListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
int userInput = 0;
try{
userInput = m_view.getGuests();
m_model.setNumOfPeople(userInput);
m_view.createTipTailoringPanel(m_model);
}
catch(NumberFormatException nfex)
{
m_view.showError("Bad input: '" + userInput + "'");
}
}
}
I suspect that your problem is outside of the code you listed. Here's a simplified working example:
public static void main(String[] args) {
JFrame frame = new JFrame();
DynamicJPanel dynamic = new DynamicJPanel();
frame.add(dynamic.createTipTailoringPanel(3));
frame.pack();
frame.setVisible(true);
}
JPanel createTipTailoringPanel(int size) {
JPanel content = new JPanel();
content.setLayout(new GridLayout(0, 4));
for (int i = 0; i < size; i++) {
content.add(new JTextField());
content.add(new JSlider());
content.add(new JLabel("$"));
content.add(new JLabel());
}
return content;
}
First, since you don't use the arrays anywhere, it could be shortened to:
JPanel createTipTailoringPanel(TipCalcModel model)
{
JPanel content = new JPanel();
int size = model.getNumOfPeople();
content.setLayout(new GridLayout(0,4));
if(size == 0)
{
return content;
}
else
{
for(int i=0; i<size; i++)
{
content.add(new JTextField());
content.add(new JSlider());
content.add(new JLabel("$"));
content.add(new JLabel());
}
return content;
}
}
Second, seems like you add an empty components to the panel, maybe that's what you actually get?
Third, add you need to add the content panel to the JFrame (or other container) once it returns from the method above.