import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.FlowLayout;public class MyClass extends JFrame
{
private JPanel panel = new JPanel();
public MyClass()
{
setTitle("测试");
panel.add(new JButton("1"));
panel.add(new JButton("221"));
panel.add(new JButton("3"));
add(panel,BorderLayout.SOUTH);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(new FlowLayout());
setResizable(false);
setSize(400,300);
setVisible(true);
} public static void main(String[] args)
{
JFrame.setDefaultLookAndFeelDecorated(true);
new MyClass();
}
}上面这段程序的效果应该是按钮将沿窗体的底部从左至右排列啊!可是怎么得不到想要的结果啊?结果还是沿窗体的顶部从左至右排列.难道两个布局合在一起不起作用吗?
import javax.swing.JButton;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.FlowLayout;public class MyClass extends JFrame
{
private JPanel panel = new JPanel();
public MyClass()
{
setTitle("测试");
panel.add(new JButton("1"));
panel.add(new JButton("221"));
panel.add(new JButton("3"));
add(panel,BorderLayout.SOUTH);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(new FlowLayout());
setResizable(false);
setSize(400,300);
setVisible(true);
} public static void main(String[] args)
{
JFrame.setDefaultLookAndFeelDecorated(true);
new MyClass();
}
}上面这段程序的效果应该是按钮将沿窗体的底部从左至右排列啊!可是怎么得不到想要的结果啊?结果还是沿窗体的顶部从左至右排列.难道两个布局合在一起不起作用吗?
import javax.swing.JButton;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.FlowLayout; public class MyClass extends JFrame
{
private JPanel panel = new JPanel();
public MyClass()
{
setTitle("测试");
panel.add(new JButton("1"));
panel.add(new JButton("221"));
panel.add(new JButton("3"));
add(panel,BorderLayout.SOUTH);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(new FlowLayout(FlowLayout.LEFT)); //需要在这里设置一下就可以了
setResizable(false);
setSize(400,300);
setVisible(true);
} public static void main(String[] args)
{
JFrame.setDefaultLookAndFeelDecorated(true);
new MyClass();
}
}
在那里看看有无能回答你的,谢谢,LZ,甭忘了给俺分哦,谢谢LZ
import javax.swing.JButton;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.FlowLayout; public class MyClass extends JFrame
{
private JPanel panel = new JPanel();
public MyClass()
{
setTitle("测试");
panel.add(new JButton("1"));
panel.add(new JButton("221"));
panel.add(new JButton("3"));
add(panel,BorderLayout.SOUTH);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(new FlowLayout(FlowLayout.LEFT)); //需要在这里设置一下就可以了
setResizable(false);
setSize(400,300);
setVisible(true);
} public static void main(String[] args)
{
JFrame.setDefaultLookAndFeelDecorated(true);
new MyClass();
}
}
import javax.swing.JButton;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.FlowLayout; public class MyClass extends JFrame
{
private JPanel panel = new JPanel();
public MyClass()
{
setTitle("测试");
setLayout(new BorderLayout());
panel.add(new JButton("1"));
panel.add(new JButton("221"));
panel.add(new JButton("3"));
add(panel,BorderLayout.SOUTH);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setResizable(false);
setSize(400,300);
setVisible(true);
} public static void main(String[] args)
{
JFrame.setDefaultLookAndFeelDecorated(true);
new MyClass();
}
} 这样就可以了,可是我想不通的是为什么FlowLayout布局不起作用
setLayout(new FlowLayout());layout被重置了