The Artima Developer Community
Sponsored Link

Java Answers Forum
JFrame error!! Please Help

1 reply on 1 page. Most recent reply: Dec 1, 2003 7:09 AM by steps

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
nawaray

Posts: 3
Nickname: menwa
Registered: Nov, 2003

JFrame error!! Please Help Posted: Nov 30, 2003 3:08 AM
Reply to this message Reply
Advertisement
hi..

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.*;

class UtilityMethods extends JFrame implements ActionListener {
private File fileName;
private RandomAccessFile output;
AudioStream voice;
UtilityMethods utilities;
Connection conn;
Statement stat;
String dsnName, userStatus;
String appTable = "CUSTOMER";
Container c = getContentPane();
JTabbedPane tabs;
JTable dataTable;
static String[][] tableData;
JScrollPane scrollpane;
JTextField id, name, address, phone, sex, dob, photo; JTextArea comments; JButton search, update, clear, add, delete, close; JPanel customerPanel;
JPanel backPanel, inputPanel, middlePanel, buttonPanel1, buttonPanel2, photoHolder;

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);

dataTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
customerPanel.add(scrollpane, BorderLayout.SOUTH);
c.add(tabs);
id.grabFocus();
pack();
repaint();
adupdateTable();
} //try
catch (Exception e) {
System.out.println("Caught updateTable exception: " + e);
}//catch
} //updatetable


steps

Posts: 14
Nickname: spanishste
Registered: Nov, 2003

Re: JFrame error!! Please Help Posted: Dec 1, 2003 7:09 AM
Reply to this message Reply
would be really interesting to know as I also had the same problem before.I solved it by disabling the maximize button, though aint it a smart way.

Flat View: This topic has 1 reply on 1 page
Topic: Whats the difference between System.arraycopy() & Object.Clone() method? Previous Topic   Next Topic Topic: array initializer

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use