i have this JFrame that has textfields located north, buttons located in the center and a JTable located south... when i run my application and maximize the page the JTable will be located on top of the buttons which will let the buttons disappear.. is there a way to let the JTable stay at its position when i mazimixe the page???? (i'm using a border Layout) thankxxx
this is my code: import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.table.*; import java.sql.*; import java.io.*; import javax.swing.JPanel; import java.applet.*; import sun.audio.*; import java.net.*; import java.text.*;
void makeGUI() { c.setLayout(new BorderLayout()); tabs = new JTabbedPane(); customerPanel = new JPanel(new BorderLayout()); adminPanel = new JPanel(new BorderLayout()); voicePanel= new JPanel(new BorderLayout());
//1. Construct customers tab: //The data input section: inputPanel = new JPanel(new GridLayout(4, 4)); id = new JTextField(20); name = new JTextField(20); address = new JTextField(20); phone = new JTextField(20); sex = new JTextField(20); dob = new JTextField(20); photo = new JTextField(20); inputPanel.add(new JLabel("CPR", JLabel.CENTER)); inputPanel.add(id); inputPanel.add(new JLabel("Name", JLabel.CENTER)); inputPanel.add(name); inputPanel.add(new JLabel("Address", JLabel.CENTER)); inputPanel.add(address); inputPanel.add(new JLabel("Phone", JLabel.CENTER)); inputPanel.add(phone); inputPanel.add(new JLabel("Sex", JLabel.CENTER)); inputPanel.add(sex); inputPanel.add(new JLabel("Date Of Birth",JLabel.CENTER)); inputPanel.add(dob); inputPanel.add(new JLabel("Customer Photo ",JLabel.CENTER)); inputPanel.add(photo); customerPanel.add(inputPanel, BorderLayout.NORTH);
//The buttons section: backPanel = new JPanel(); middlePanel = new JPanel(new BorderLayout()); buttonPanel1 = new JPanel(); buttonPanel2 = new JPanel(); search = new JButton("SEARCH"); update = new JButton("UPDATE"); clear = new JButton("CLEAR"); add = new JButton("ADD"); delete = new JButton("DELETE"); close = new JButton("EXIT"); search.setPreferredSize(new Dimension(102, 26)); update.setPreferredSize(new Dimension(102, 26)); clear.setPreferredSize(new Dimension(102, 26)); add.setPreferredSize(new Dimension(102, 26)); delete.setPreferredSize(new Dimension(102, 26)); close.setPreferredSize(new Dimension(102, 26)); search.addActionListener(this); update.addActionListener(this); clear.addActionListener(this); add.addActionListener(this); delete.addActionListener(this); close.addActionListener(this); buttonPanel1.add(search); buttonPanel1.add(update); buttonPanel1.add(clear); buttonPanel2.add(add); buttonPanel2.add(delete); buttonPanel2.add(close); middlePanel.add(buttonPanel1, BorderLayout.NORTH); middlePanel.add(buttonPanel2, BorderLayout.CENTER); photoHolder = new JPanel(); Icon curPhoto = new ImageIcon(""); Icon[] custPhotos = {curPhoto}; JList photosList = new JList(custPhotos); photosList.setFixedCellHeight(100); photosList.setFixedCellWidth(80); photoHolder.add(photosList); makeComments(); backPanel.add(middlePanel); backPanel.add(photoHolder); backPanel.add(comments); customerPanel.add(backPanel,BorderLayout.CENTER); }
//Update the customer table from the database: void updateTable(String userStatus) { this.userStatus = userStatus; updateTable(); } void updateTable() { ResultSet results = null; ResultSet results1 = null; try { //Get the number of rows in the table so we know how big to make the data array.. int rowNumbers = 0; int columnCount = 6; results = stat.executeQuery("SELECT COUNT(*) FROM CUSTOMER "); if(results.next()) { rowNumbers = results.getInt(1); } //if if(rowNumbers == 0) rowNumbers = 1; tableData = new String[rowNumbers][columnCount]; //Initialize the data array with "" so we avoid possibly having nulls in it later.. for(int i =0;i<tableData.length;i++) { for(int j=0;j<tableData[0].length;j++) tableData[j] = ""; } //Populate the data array with results of the query on the database.. int currentRow = 0; results1 = stat.executeQuery("SELECT * FROM CUSTOMER ORDER BY ID"); while (results1.next()) { for(int i = 0; i < columnCount; i++) tableData[currentRow] = results1.getString(i + 1); currentRow++; } //while //---------------------------------------------------------------------------- ------------------------- //Create the table model: final String[] colName = { "CPR", "Name", "Address", "Phone", "Sex", "Date OF Birth" }; TableModel pageModel = new AbstractTableModel() { public int getColumnCount() { return tableData[0].length; } //getColumnCount public int getRowCount() { return tableData.length; } //getRowCount public Object getValueAt(int row, int col) { return tableData[row][col]; } //getValueAt public String getColumnName(int column) { return colName[column]; } //getcolName public Class getColumnClass(int col) { return getValueAt(0, col).getClass(); } //getColumnClass public boolean isCellEditable(int row, int col) { return false; } //isCellEditable public void setValueAt(String aValue, int row, int column) { tableData[row][column] = aValue; } //pageModel //----------------------------------------------------------------------------- ------------------------ //Create the JTable from the table model: dataTable = new JTable(pageModel); //---------------------------------------------------------------------------- ------------------------- / scrollpane = new JScrollPane(dataTable); //scrollpane.setVisible(true); if (inputPanel == null) makeGUI(); JScrollPane scrollpane = new JScrollPane(dataTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);