Graphics
import javax.swing.*;import java.awt.*;
public class G extends JFrame
{
public G()
{
setLayout(new GridLayout());
JPanel p1 = new JPanel(new GridLayout(2, 1));
JPanel p2 = new JPanel(new BorderLayout());
p1.add(new JButton("B1"));
p2.add(p1, BorderLayout.EAST);
add(p2, BorderLayout.NORTH);
add(new JButton("B2"), BorderLayout.WEST);
}
public static void main(String[] args)
{
G g = new G();
g.setSize(100, 100);
g.setLocationRelativeTo(null);
g.setVisible(true);
LayoutManager l = g.getLayout();
if (l instanceof FlowLayout)
{
System.out.println("l is FlowLayout\n");
}
if (l instanceof GridLayout)
{
System.out.println("l is FlowLayout\n");
}
if (l instanceof BorderLayout)
{
System.out.println("l is FlowLayout\n");
}
}
}
运行结果是:l is FlowLayout。
但明明用了setLayout(new GridLayout());但为什么结果是那样的? --------------------编程问答-------------------- 看题目 我以为是神马的套图 =。= --------------------编程问答-------------------- 代码打错了,请无视这个帖子。
--------------------编程问答--------------------
刚把代码复制出来……
补充:Java , Java SE