public class Login extends JFrame implements ActionListener { private JTable table;
public int i; public String name; public String address; public String code; public String tel; public String sex; /** * Creates new form NewJFrame1 */ public Login() { initComponents(); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { adminlogin = new javax.swing.JButton(); admincancel = new javax.swing.JButton(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); adminname = new javax.swing.JTextField(); adminpass = new javax.swing.JPasswordField(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); adminlogin.setText("登录");
猜测是你的表格大小存在问题,使得其它控件与表格重叠,
建议:正确设置布局,调整各控件的大小
感觉最好还是把代码贴出来看看……
String[] columnNames={"id","mobile","email","name","birday","address","code","tel","sex"}; //列名
try {
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(new File("d:\\xml.xml"));
Element root1 = doc.getRootElement();
List<Element> list = root1.getChildren();
int count = list.size(); //统计个数
Object[][] rowData=new Object[count][9]; //表格数据
int i = 0; //遍历集合*****不知java中如何取得key暂时采用i++
for(Element el : list) {
String id1 = el.getAttributeValue("id");
String mobile1 = el.getChildText("mobile");
String email1 = el.getChildText("email");
String name1 = el.getChildText("name");
String birday1 = el.getChildText("birday");
String adress1 = el.getChildText("address");
String code1 = el.getChildText("code");
String tel1 = el.getChildText("tel");
String sex1 = el.getChildText("sex");
rowData[i][0]=id1; //初始化数组内容
rowData[i][1] = mobile1;
rowData[i][2]=email1; //初始化数组内容
rowData[i][3]=name1; //初始化数组内容
rowData[i][4]=birday1; //初始化数组内容
rowData[i][5]=adress1; //初始化数组内容
rowData[i][6]=code1; //初始化数组内容
rowData[i][7]=tel1; //初始化数组内容
rowData[i][8]=sex1; //初始化数组内容
i++;
}
Container container=getContentPane(); //获取窗口容器
table=new JTable(rowData,columnNames); //实例化表格
alter.setBounds(620,510,60,30);
del.setBounds(700,510,60,30);
allcount.setText("共有"+count+"会员");
allcount.setBounds(500,510,80,30);
//添加事件
del.addActionListener(this);
alter.addActionListener(this);
search.addActionListener(this);
countwhere.addActionListener(this);
//设置按钮间距
searchnamelabel.setBounds(50,510,60,30);
searchname.setBounds(110,510,160,30);
search.setBounds(290,510,60,30);
wherestart.setBounds(20,460,80,30);
category1.setBounds(100,460,60,30);
whereend.setBounds(180,460,80,30);
countwhere.setBounds(280,460,80,30);
container.setLayout(new BorderLayout());
container.add(alter);
container.add(del);
//添加到container
container.add(searchnamelabel);
container.add(searchname);
container.add(search);
container.add(allcount);
container.add(category1);
container.add(wherestart);
container.add(whereend);
container.add(countwhere);
container.add(new JScrollPane(table),BorderLayout.CENTER); //增加组件
} catch (Exception e) {
// TODO: handle exception
}
setSize(800,600); //设置窗口尺寸
setVisible(true); //设置窗口可视
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //关闭窗口时退出程序
}这个是窗口的代码
你都是用setBounds来固定组建位置了,为什么还要用BorderLayout布局了?这样setBounds就不起作用了。这样试试container.setLayout(null)
private JTable table;
public int i;
public String name;
public String address;
public String code;
public String tel;
public String sex;
/**
* Creates new form NewJFrame1
*/
public Login() {
initComponents();
} /**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
adminlogin = new javax.swing.JButton();
admincancel = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
adminname = new javax.swing.JTextField();
adminpass = new javax.swing.JPasswordField(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); adminlogin.setText("登录");
adminlogin.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
adminloginActionPerformed(evt);
}
}); admincancel.setText("取消");
admincancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
admincancelActionPerformed();
}
}); jLabel1.setText("用户名"); jLabel2.setText("密码"); jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("./c_logo2012.png"))); // NOI18N
jLabel3.setText("jLabel3"); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(80, 80, 80)
.addComponent(adminlogin)
.addGap(83, 83, 83)
.addComponent(admincancel))
.addGroup(layout.createSequentialGroup()
.addGap(86, 86, 86)
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(48, 48, 48)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(adminpass, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(40, 40, 40)
.addComponent(adminname, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE)))))
.addContainerGap(63, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(adminname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(30, 30, 30)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(adminpass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(32, 32, 32)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(adminlogin)
.addComponent(admincancel))
.addContainerGap(43, Short.MAX_VALUE))
); pack();
}// </editor-fold>
//响应登录事件
private void adminloginActionPerformed(java.awt.event.ActionEvent evt) {
String adminlogin1 = adminname.getText();
char[] adminpass1 = adminpass.getPassword();
String adminpass = new String(adminlogin1);
String adminusername = "admin";
String adminuserpass = "admin";
//判读用户账号
if (adminlogin1.equals(adminusername) && adminpass.equals(adminuserpass)) {
JOptionPane.showMessageDialog(null, "密码输入正确");
viewuserinfo();
} else {
JOptionPane.showMessageDialog(null, "用户名或密码错误");
}
}这个登录的码
if (adminlogin1.equals(adminusername) && adminpass.equals(adminuserpass)) {
JOptionPane.showMessageDialog(null, "密码输入正确"); // 这里添加登录控件的隐藏代码
................
viewuserinfo();
}