其实是标题党了..我有一个问题想请教一下,所以弄了一个很大的标题,望见谅故事的名字是:我用的是null布局,做的是一个 文件分割器
一个大框,两个界面,每个界面内有数个器件,我的思路是,几个器件放在一个子面板内,然后把子面板添加到界面上
很简单的我大一...但是结果是界面乱,根本没有排布,原因可能是没有设置器件或者是子界面坐标setBounds(),我不知道该放到哪里...希望CSDN的大哥大嫂们给力啊,在线等..
import java.awt.*;
import javax.swing.*;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.*;
import java.io.*;
public class File_Cutter extends JFrame
{
private static final long serialVersionUID = 1L;
private JTabbedPane choic = new JTabbedPane();
private File_C fcp = new File_C();
private File_M fmp = new File_M();
{
       
choic.add("File Cut", this.fcp);
//this.fcp.setLayout(null);
choic.add("File Merge", this.fmp);
//this.fmp.setLayout(null);

}
public File_Cutter()
{

super("File cutter");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setBounds(800, 100, 600, 545);  
this.setResizable(false);  
this.add(choic);

this.setVisible(true);
}
public static void main(String[] args)
{

new File_Cutter();
}}
class File_C extends JPanel
{
/*各类子面板*/
private static final long serialVersionUID = 2L;
private JPanel sp1 = new JPanel();
private JPanel sp2 = new JPanel();
private JPanel sp3 = new JPanel();
private JPanel sp4 = new JPanel();
private JPanel sp5 = new JPanel();
private JPanel sp6 = new JPanel();




protected JLabel lb1 = new JLabel("File Name:");
   
protected JTextField tf1 = new JTextField(30);
protected JButton bu1=new JButton("...");

protected JLabel lb2=new JLabel("File Size:");
protected JTextField tf2 = new JTextField(30);

protected JLabel lb3=new JLabel("Block Size:");
protected JRadioButton rb1=new JRadioButton("1.4MB");
protected JRadioButton rb2=new JRadioButton("1.2MB");
protected JRadioButton rb3=new JRadioButton("720KB");
protected JRadioButton rb4=new JRadioButton("360KB");
protected JRadioButton rb5=new JRadioButton("Self defined:");
protected JTextField tf3 = new JTextField(8);
protected JLabel lb4 = new JLabel("KB");
protected ButtonGroup group=new ButtonGroup();
{
group.add(rb1);
group.add(rb2);
group.add(rb3);
group.add(rb4);
group.add(rb5);

}
protected JLabel lb5 = new JLabel("Number of blocks:");
protected JTextField tf4 = new JTextField(30);
protected JLabel lb6 = new JLabel("Target file:");
protected JTextField tf5 = new JTextField(30);
protected JButton bu2=new JButton("...");
protected JButton bu3=new JButton("Start Cutter");
protected JProgressBar pb=new JProgressBar();
{
pb.setStringPainted(true);
}


public File_C()
{

addSp1();
addSp2();
addSp3();
addSp4();
addSp5();
this.add(sp1);

this.add(sp2);

this.add(sp3);
this.add(sp4);
this.add(sp5);
this.add(sp6);
}
public void addSp1()
{
this.sp1.add(this.lb1);

this.sp1.add(this.tf1);
this.sp1.add(this.bu1);
}
public void addSp2()
{
this.sp1.add(this.lb2);
this.sp1.add(this.tf2);
}
public void addSp3()
{
this.sp3.add(this.lb3);
this.sp3.add(this.rb1);
this.sp3.add(this.rb2);
this.sp3.add(this.rb3);
this.sp3.add(this.rb4);
this.sp3.add(this.rb5);
this.sp3.add(this.tf3);
this.sp3.add(this.lb4);
}
public void addSp4()
{
this.sp4.add(this.lb5);
this.sp4.add(this.tf4); }
public void addSp5()
{
this.sp5.add(this.lb6);
this.sp5.add(this.tf5);
this.sp5.add(this.bu2); }
public void addSp6()
{
this.sp6.add(this.bu3);
this.sp6.add(this.pb);
}
}
class File_M extends JPanel
{
private static final long serialVersionUID = 3L;
private JPanel sp1 = new JPanel();
private JPanel sp2 = new JPanel();
private JPanel sp3 = new JPanel();
private JPanel sp4 = new JPanel();
private JPanel sp5 = new JPanel();
protected JLabel lb1 = new JLabel("File Name:");
protected JTextField tf1 = new JTextField(30);
protected JButton bu1=new JButton("...");
protected JLabel lb2 = new JLabel("File to be merged");
protected JTextArea ta=new JTextArea(10,30);
protected JScrollPane sp = new JScrollPane(ta,ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
{
ta.setEditable(false);
ta.setLineWrap(true);
ta.setWrapStyleWord(true); }
protected JLabel lb3 = new JLabel("Number of files:");
protected JTextField tf2 = new JTextField(30);
protected JButton bu2=new JButton("Remove");
protected JButton bu3=new JButton("Clear");
protected JLabel lb4 = new JLabel("Target file");
protected JTextField tf3 = new JTextField(30);
protected JButton bu4= new JButton("Start merging");
protected JProgressBar pb = new JProgressBar(); public File_M()
{
addSp1();
addSp2();
addSp3();
addSp4();
addSp5();
this.add(sp1);
this.add(sp2);
this.add(sp3);
this.add(sp4);
this.add(sp5);

}
public void addSp1()
{
this.sp1.add(this.lb1);
this.sp1.add(this.tf1);
this.sp1.add(this.bu1);
}
public void addSp2()
{
this.sp2.add(this.lb2);
this.sp2.add(this.sp);
}
public void addSp3()
{
this.sp3.add(this.lb3);
this.sp3.add(this.tf2);
this.sp3.add(this.bu2);
this.sp3.add(this.bu3);
}
public void addSp4()
{
this.sp4.add(this.lb4);
this.sp4.add(this.tf3);
}
public void addSp5()
{
this.sp5.add(this.bu4);
this.sp5.add(this.pb);
}
}