位奇怪的,如果看到我做到以下几点:的Java Swing - 在使用布局奇怪不同的布局管理器
import javax.swing.*;
public class FunkyButtonLayout {
public static void main(String[] args) {
JFrame frame = new JFrame("");
JPanel j0 = new JPanel(); // j0 gets added to the root pane
j0.setLayout(null);
JPanel j1 = new JPanel(); // j1 gets added to j0
j1.setLayout(null);
JButton b1 = new JButton(""); // b1 gets added to j1
j1.add(b1);
b1.setBounds(0, 0, 40, 32); // b1 is big
j0.add(j1);
j1.setBounds(0, 0, 32, 32); // j1 is not so big - b1 gets 'trimmed'
frame.getContentPane().setLayout(null); // <- seems to be needed :-(
frame.getContentPane().add(j0);
j0.setBounds(10, 10, 32, 32); // end result: a 32x32 button with
frame.setSize(125, 125); // a trimmed right border
frame.setVisible(true); // in the top-left corner
}
}
我得到差不多就是我要找的,除了在定位J0的能力带有布局管理器的根窗格。如果我改变
frame.getContentPane().setLayout(null);
线
frame.getContentPane().setLayout(new java.awt.FlowLayout());
我看到J0画为1x1像素@屏幕中间:-(
任何想法,为什么?请注意,这ISN”只是一个FlowLayout的东西 - 几乎所有的布局管理器弄乱了这一点。
我真的想要“边界修剪在一边”按钮的净效应 - 它允许我做工具栏按钮集群的事情(cage fighter试图摆脱的东西)与本机外观按钮控制 - 我看不到另一种方式做到这一点,感谢OS级皮肤。因此,任何想法赞赏:-)
你达人!那么,几乎;-)“按照他们打算使用的方式使用布局管理器”并不会给我带来我所需要的破解。 但是,添加\t j0.setPreferredSize(new java.awt.Dimension(32,32));在j0.setBounds行解决问题之后。 谢谢!!!!! – 2009-02-12 01:23:21