2 luyuxianseng luyuxianseng 于 2016.04.10 16:59 提问

关于java swing 为什么界面空白

package com.bbm.view;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.HeadlessException;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.border.TitledBorder;

public class BookBorrow extends JFrame {

private static final long serivaVersionUID = 1L;
private JPanel readerborrow_infoJP,bookborrowJP,buttonJP,readerinfoJP,reader_resultJP;
private JScrollPane jscrollPane;
private JTable jtable;
private JLabel readeridJL,readernameJL,readertypeJL,ISBNJL,booktypeJL,booknameJL,authorJL,publishJL,publishdateJL,printtimeJL,unitpriceJL,nowdateJL,operatorJL;
private JTextField readeridJTF,readernameJTF,readertypeJTF,ISBNJTF,booktypeJTF,booknameJTF,authorJTF,publishJTF,publishdateJTF,printtimeJTF,unitpriceJTF,nowdateJTF,operatorJTF;
private JButton borrowJB,closeJB;

public BookBorrow(){
    setBounds(200,200,700,700);
    setTitle("图书借阅");
    readerborrow_infoJP = new JPanel(new BorderLayout());
    TitledBorder tb1 = new TitledBorder("读者借阅信息");
    readerborrow_infoJP.setBorder(tb1);
    readerinfoJP = new JPanel();
    readeridJL = new JLabel("读者编号:");
    readeridJL.setHorizontalAlignment(SwingConstants.CENTER);
    readerinfoJP.add(readeridJL);
    readeridJTF = new JTextField();
    readeridJTF.setColumns(10);
    readerinfoJP.add(readeridJTF);
    readernameJL = new JLabel("读者姓名:");
    readernameJL.setHorizontalAlignment(SwingConstants.CENTER);
    readerinfoJP.add(readernameJL);
    readernameJTF = new JTextField();
    readernameJTF.setColumns(10);
    readerinfoJP.add(readernameJTF);
    readertypeJL = new JLabel("读者类别:");
    readertypeJL.setHorizontalAlignment(SwingConstants.CENTER);
    readerinfoJP.add(readertypeJL);
    readertypeJTF = new JTextField();
    readertypeJTF.setColumns(10);
    readerinfoJP.add(readertypeJTF);
    readerborrow_infoJP.add(readerinfoJP,BorderLayout.NORTH);

    reader_resultJP = new JPanel();
    jscrollPane = new JScrollPane();
    jscrollPane.setPreferredSize(new Dimension(400,200));
    jtable = new JTable();
    jtable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    jscrollPane.setViewportView(jtable);
    reader_resultJP.add(jscrollPane);
    readerborrow_infoJP.add(reader_resultJP,BorderLayout.CENTER);
    this.add(readerborrow_infoJP,BorderLayout.NORTH);

    bookborrowJP = new JPanel();
    TitledBorder tb2 = new TitledBorder("图书借阅");
    bookborrowJP.setBorder(tb2);
    GridLayout gridLayout = new GridLayout(5, 4, 8, 8);
    bookborrowJP.setLayout(getLayout());
    ISBNJL = new JLabel("ISBN:");
    ISBNJL.setHorizontalAlignment(SwingConstants.CENTER);
    bookborrowJP.add(ISBNJL);
    ISBNJTF = new JTextField();
    bookborrowJP.add(ISBNJTF);
    booktypeJL = new JLabel("类别:");
    booktypeJL.setHorizontalAlignment(SwingConstants.CENTER);
    bookborrowJP.add(booktypeJL);
    booktypeJTF = new JTextField();
    bookborrowJP.add(booktypeJTF);
    booknameJL = new JLabel("书名:");
    booknameJL.setHorizontalAlignment(SwingConstants.CENTER);
    bookborrowJP.add(booknameJL);
    booknameJTF = new JTextField();
    bookborrowJP.add(booknameJTF);
    authorJL = new JLabel("作者:");
    authorJL.setHorizontalAlignment(SwingConstants.CENTER);
    bookborrowJP.add(authorJL);
    authorJTF = new JTextField();
    bookborrowJP.add(authorJTF);
    publishJL = new JLabel("出版社:");
    publishJL.setHorizontalAlignment(SwingConstants.CENTER);
    bookborrowJP.add(publishJL);
    publishJTF = new JTextField();
    bookborrowJP.add(publishJTF);
    publishdateJL = new JLabel("出版日期:");
    publishdateJL.setHorizontalAlignment(SwingConstants.CENTER);
    bookborrowJP.add(publishdateJL);
    publishdateJTF = new JTextField();
    bookborrowJP.add(publishdateJTF);
    printtimeJL = new JLabel("印刷次数:");
    printtimeJL.setHorizontalAlignment(SwingConstants.CENTER);
    bookborrowJP.add(printtimeJL);
    printtimeJTF = new JTextField();
    bookborrowJP.add(printtimeJTF);
    unitpriceJL = new JLabel("单价:");
    unitpriceJL.setHorizontalAlignment(SwingConstants.CENTER);
    unitpriceJTF = new JTextField();
    bookborrowJP.add(unitpriceJTF);
    nowdateJL = new JLabel("当前日期:");
    nowdateJL.setHorizontalAlignment(SwingConstants.CENTER);
    bookborrowJP.add(nowdateJL);
    nowdateJTF = new JTextField();
    bookborrowJP.add(nowdateJTF);
    operatorJL = new JLabel("操作人员:");
    operatorJL.setHorizontalAlignment(SwingConstants.CENTER);
    bookborrowJP.add(operatorJL);
    operatorJTF = new JTextField();
    bookborrowJP.add(operatorJTF);
    this.add(bookborrowJP,BorderLayout.CENTER);

    buttonJP = new JPanel();
    borrowJB = new JButton("借阅");
    closeJB = new JButton("关闭");
    buttonJP.add(borrowJB);
    buttonJP.add(closeJB);
    this.add(buttonJP,BorderLayout.SOUTH);

    this.setVisible(true);
    this.setResizable(false);
}

public static void main(String[] args) {
    new BookBorrow();

}

}

2个回答

CSDNXIAOD
CSDNXIAOD   2016.04.10 17:12

java swing 登陆界面
java swing 界面风格
java swing 界面开发实战
----------------------biu~biu~biu~~~在下问答机器人小D,这是我依靠自己的聪明才智给出的答案,如果不正确,你来咬我啊!

a172586418
a172586418   2016.04.10 21:18

首先,你需要确定,窗体设置Size了么,其次控件都添加到this里面了么。
JProgressBar bar;
JLabel label;
int width,height;
public IndexView()
{
label = new JLabel(new ImageIcon("image/index/index.jpg"));

    bar = new JProgressBar();
    bar.setStringPainted(true);
    bar.setIndeterminate(false);
    bar.setBackground(Color.darkGray);

    this.add(label,BorderLayout.NORTH);
    this.add(bar, BorderLayout.SOUTH);

    this.setSize(400, 263);
    width = Toolkit.getDefaultToolkit().getScreenSize().width;
    height = Toolkit.getDefaultToolkit().getScreenSize().height;
    this.setLocation(width/2-200, height/2-150);

    this.setVisible(true);
}

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!