java panel 中label为何不能显示全??
//创建新的窗口Frameframe=newFrame("工作窗口");//GridLayoutGlayout=newGridLayout(4,0);Panelp1=ne...
//创建新的窗口
Frame frame = new Frame("工作窗口");
//GridLayout Glayout = new GridLayout(4, 0);
Panel p1 = new Panel();
Panel p2 = new Panel();
Panel p3 = new Panel();
Panel p4 = new Panel();
Panel basePan = new Panel();
basePan.setLayout(new BoxLayout(basePan, BoxLayout.Y_AXIS));
basePan.add(p1);
basePan.add(p2);
basePan.add(p3);
basePan.add(p4);
basePan.setSize(800, 600);
yesBtn = new Button("是");
noBtn = new Button("否");
percentLab = new Label("XX/XX X%");
contentLab = new Label("---读取到内容---");
Label addLab = new Label("内容前添加:");
final TextField filePathTF = new TextField(15);
StringBuffer writeBuf = new StringBuffer(""); /*用来向文件写入*/
String readContent = ""; /*存储读取到的一行内容*/
totalLine = getFileLineCounts(openFilePath);
try {
reader = new FileReader(openFilePath);
bufRead = new BufferedReader(reader);
readLineCnt++;
readContent = bufRead.readLine();
contentLab.setText(readContent);
System.out.println(readContent);
percentLab.setText(""+readLineCnt+" / " + totalLine + " " + myPercent(readLineCnt, totalLine));
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
percentLab.setFont(new Font("Serif", Font.PLAIN, 25));
percentLab.setAlignment(Label.CENTER);
percentLab.setVisible(true);
p1.add(percentLab);
p2.setBackground(Color.CYAN);
contentLab.setFont(new Font("Serif", Font.PLAIN, 30));
contentLab.setAlignment(Label.CENTER);
contentLab.setVisible(true);
p2.add(contentLab);
addLab.setFont(new Font("Serif", Font.PLAIN, 15));
addLab.setVisible(true);
filePathTF.setVisible(true);
p3.add(addLab);
p3.add(filePathTF);
yesBtn.setFont(new Font("Serif", Font.PLAIN, 40));
noBtn.setFont(new Font("Serif", Font.PLAIN, 40));
p4.add(yesBtn);
p4.add(noBtn);
frame.setLayout(new FlowLayout());
frame.setLocation(500, 300); //设置在屏幕的位置
frame.setSize(800, 600); //窗体大小
frame.setResizable(false);
frame.add(basePan);
//显示窗体
frame.setVisible(true);
/*----------------------------------*/
最后显示的contentLabel只能显示一部分?如图: 展开
Frame frame = new Frame("工作窗口");
//GridLayout Glayout = new GridLayout(4, 0);
Panel p1 = new Panel();
Panel p2 = new Panel();
Panel p3 = new Panel();
Panel p4 = new Panel();
Panel basePan = new Panel();
basePan.setLayout(new BoxLayout(basePan, BoxLayout.Y_AXIS));
basePan.add(p1);
basePan.add(p2);
basePan.add(p3);
basePan.add(p4);
basePan.setSize(800, 600);
yesBtn = new Button("是");
noBtn = new Button("否");
percentLab = new Label("XX/XX X%");
contentLab = new Label("---读取到内容---");
Label addLab = new Label("内容前添加:");
final TextField filePathTF = new TextField(15);
StringBuffer writeBuf = new StringBuffer(""); /*用来向文件写入*/
String readContent = ""; /*存储读取到的一行内容*/
totalLine = getFileLineCounts(openFilePath);
try {
reader = new FileReader(openFilePath);
bufRead = new BufferedReader(reader);
readLineCnt++;
readContent = bufRead.readLine();
contentLab.setText(readContent);
System.out.println(readContent);
percentLab.setText(""+readLineCnt+" / " + totalLine + " " + myPercent(readLineCnt, totalLine));
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
percentLab.setFont(new Font("Serif", Font.PLAIN, 25));
percentLab.setAlignment(Label.CENTER);
percentLab.setVisible(true);
p1.add(percentLab);
p2.setBackground(Color.CYAN);
contentLab.setFont(new Font("Serif", Font.PLAIN, 30));
contentLab.setAlignment(Label.CENTER);
contentLab.setVisible(true);
p2.add(contentLab);
addLab.setFont(new Font("Serif", Font.PLAIN, 15));
addLab.setVisible(true);
filePathTF.setVisible(true);
p3.add(addLab);
p3.add(filePathTF);
yesBtn.setFont(new Font("Serif", Font.PLAIN, 40));
noBtn.setFont(new Font("Serif", Font.PLAIN, 40));
p4.add(yesBtn);
p4.add(noBtn);
frame.setLayout(new FlowLayout());
frame.setLocation(500, 300); //设置在屏幕的位置
frame.setSize(800, 600); //窗体大小
frame.setResizable(false);
frame.add(basePan);
//显示窗体
frame.setVisible(true);
/*----------------------------------*/
最后显示的contentLabel只能显示一部分?如图: 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询