问题描述
- 关于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_infoJPbookborrowJPbuttonJPreaderinfoJPreader_resultJP;private JScrollPane jscrollPane;private JTable jtable;private JLabel readeridJLreadernameJLreadertypeJLISBNJLbooktypeJLbooknameJLauthorJLpublishJLpublishdateJLprinttimeJLunitpriceJLnowdateJLoperatorJL;private JTextField readeridJTFreadernameJTFreadertypeJTFISBNJTFbooktypeJTFbooknameJTFauthorJTFpublishJTFpublishdateJTFprinttimeJTFunitpriceJTFnowdateJTFoperatorJTF;private JButton borrowJBcloseJB;public BookBorrow(){ setBounds(200200700700); 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(readerinfoJPBorderLayout.NORTH); reader_resultJP = new JPanel(); jscrollPane = new JScrollPane(); jscrollPane.setPreferredSize(new Dimension(400200)); jtable = new JTable(); jtable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); jscrollPane.setViewportView(jtable); reader_resultJP.add(jscrollPane); readerborrow_infoJP.add(reader_resultJPBorderLayout.CENTER); this.add(readerborrow_infoJPBorderLayout.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(bookborrowJPBorderLayout.CENTER); buttonJP = new JPanel(); borrowJB = new JButton(""借阅""); closeJB = new JButton(""关闭""); buttonJP.add(borrowJB); buttonJP.add(closeJB); this.add(buttonJPBorderLayout.SOUTH); this.setVisible(true); this.setResizable(false);}public static void main(String[] args) { new BookBorrow();}
}
解决方案
java swing 登陆界面
java swing 界面风格
java swing 界面开发实战
解决方案二:
首先,你需要确定,窗体设置Size了么,其次控件都添加到this里面了么。
JProgressBar bar;
JLabel label;
int widthheight;
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(labelBorderLayout.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);}
时间: 2024-12-31 19:49:57