多个JPanel在一个JFrame上。JPanel之间的距离怎么控制?

dongbremen 2008-03-12 09:14:11
菜鸟问!多个JPanel在一个JFrame上。JPanel之间的距离怎么控制?每个JPanel 的边框怎么画出来?程序运行后想看到 5个不同 JPanel之间的明显的隔离带,也就是边线!谢谢大侠啦!


import com.borland.jbcl.layout.*;
import java.awt.*;
import javax.swing.*;

public class MainFrame extends JFrame {
XYLayout xYLayout1 = new XYLayout();
JPanel jPanel1 = new JPanel();
JPanel jPanel2 = new JPanel();
JButton jButton1 = new JButton();
JTextField jTextField1 = new JTextField();
JPanel jPanel3 = new JPanel();
JPanel jPanel4 = new JPanel();
JPanel jPanel5 = new JPanel();
JButton jButton2 = new JButton();
JButton jButton3 = new JButton();
JButton jButton4 = new JButton();
public MainFrame() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
this.getContentPane().setLayout(xYLayout1);
jButton1.setBounds(new Rectangle(42, 54, 71, 23));
jButton1.setText("jButton1");
jPanel1.setLayout(null);
jPanel2.setLayout(null);
jTextField1.setText("jTextField1");
jTextField1.setBounds(new Rectangle(45, 86, 62, 20));
jPanel3.setLayout(null);
jPanel4.setLayout(null);
jPanel5.setLayout(null);
jButton2.setBounds(new Rectangle(42, 26, 71, 23));
jButton2.setText("jButton2");
jButton3.setBounds(new Rectangle(59, 36, 71, 23));
jButton3.setText("jButton3");
jButton4.setBounds(new Rectangle(63, 28, 71, 23));
jButton4.setText("jButton4");
xYLayout1.setWidth(480);
xYLayout1.setHeight(339);
this.getContentPane().add(jPanel1, new XYConstraints(5, 2, 153, 128));
jPanel1.add(jButton1, null);
this.getContentPane().add(jPanel2, new XYConstraints(7, 141, 187, 147));
jPanel2.add(jTextField1, null);
this.getContentPane().add(jPanel3, new XYConstraints(243, 22, 147, 72));
jPanel3.add(jButton2, null);
this.getContentPane().add(jPanel4, new XYConstraints(238, 108, 159, 84));
jPanel4.add(jButton3, null);
this.getContentPane().add(jPanel5, new XYConstraints(234, 203, 165, 87));
jPanel5.add(jButton4, null);
}
}

下面的是大侠老紫竹的上个帖子的提示·············································································

你把jbuilder/lib 下面的 jbcl.jar 导入到 eclipse的build path里面就可以了!

如果不知道怎么添加自己的类库,请参考这个
http://www.java2000.net/viewthread.jsp?tid=463
如果找不到,也可以到这里下载,点那个download
http://cougaar.org/cgi-bin/viewcvs.cgi/CougaarUnit/lib/jbcl.jar?cvsroot=cougaarunit·老紫竹
www.java2000.net·
.........................................................................................................
...全文
722 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
jy02411368 2008-03-12
  • 打赏
  • 举报
回复
建议你拿开发工具 好了这样的话就把复杂的事情变的很简单 当然你觉的有必要使用记事本式来写程序的话当然更好.这个JPLANE的代码并不是你看见的实际坐标 如果你是想把他们每个放在一个地方不重叠的话改坐标吧 如果要全都放在一起呵呵我想你也不会想那样做 因为实在太愚蠢了
private void jbInit() throws Exception {
this.getContentPane().setLayout(xYLayout1);
jButton1.setBounds(new Rectangle(42, 54, 71, 23));
jButton1.setText("jButton1");
jPanel1.setLayout(null);
jPanel2.setLayout(null);
jTextField1.setText("jTextField1");
jTextField1.setBounds(new Rectangle(45, 86, 62, 20));
jPanel3.setLayout(null);
jPanel4.setLayout(null);
jPanel5.setLayout(null);
jButton2.setBounds(new Rectangle(49, 26, 61, 23));
jButton2.setText("jButton2");
jButton3.setBounds(new Rectangle(60, 36, 71, 33));
jButton3.setText("jButton3");
jButton4.setBounds(new Rectangle(80, 48, 81, 43));
jButton4.setText("jButton4");
xYLayout1.setWidth(480);
xYLayout1.setHeight(339);
this.getContentPane().add(jPanel1, new XYConstraints(10, 5, 153, 128));
jPanel1.add(jButton1, null);
this.getContentPane().add(jPanel2, new XYConstraints(20, 141, 187, 147));
jPanel2.add(jTextField1, null);
this.getContentPane().add(jPanel3, new XYConstraints(200, 252, 147, 72));
jPanel3.add(jButton2, null);
this.getContentPane().add(jPanel4, new XYConstraints(263, 108, 159, 84));
jPanel4.add(jButton3, null);
this.getContentPane().add(jPanel5, new XYConstraints(234, 213, 165, 87));
jPanel5.add(jButton4, null);
}
aaaaa6794 2008-03-12
  • 打赏
  • 举报
回复
JPanel可以设置边框样式和title位置的
例:
Border backline=BorderFactory.createLineBorder(Color.black);//创建边框线样式
TitledBorder titledborder=new TitledBorder(backline,"title",TitledBorder.LEFT,TitledBorder.CENTER);
jPanel.setBorder(titledborder);//设置边框

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧