public class JXCInfo {
private JLabel backLabel;
private JDesktopPane desktopPane;
private JFrame frame;
public JXCInfo(){
frame=new JFrame("信息管理部进销存系统");
frame.addComponentListener(new FrameListener());
frame.getContentPane().setLayout(new BorderLayout());
frame.setBounds(100, 100, 800, 600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
backLabel=new JLabel();
backLabel.setVerticalAlignment(SwingConstants.TOP);
backLabel.setHorizontalAlignment(SwingConstants.CENTER);
this.updateBackImage();
desktopPane=new JDesktopPane();
desktopPane.add(backLabel,new Integer(Integer.MIN_VALUE));
frame.getContentPane().add(backLabel);
JTabbedPane navigationPanel=createNavigationPanel();
frame.setVisible(true);
}
}
书上看到的实例代码
请问加红的那句话有什么用,特别是new Integer(Integer.MIN_VALUE)中的Integer.MIN_VALUE,不知道什么意思
private JLabel backLabel;
private JDesktopPane desktopPane;
private JFrame frame;
public JXCInfo(){
frame=new JFrame("信息管理部进销存系统");
frame.addComponentListener(new FrameListener());
frame.getContentPane().setLayout(new BorderLayout());
frame.setBounds(100, 100, 800, 600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
backLabel=new JLabel();
backLabel.setVerticalAlignment(SwingConstants.TOP);
backLabel.setHorizontalAlignment(SwingConstants.CENTER);
this.updateBackImage();
desktopPane=new JDesktopPane();
desktopPane.add(backLabel,new Integer(Integer.MIN_VALUE));
frame.getContentPane().add(backLabel);
JTabbedPane navigationPanel=createNavigationPanel();
frame.setVisible(true);
}
}
书上看到的实例代码
请问加红的那句话有什么用,特别是new Integer(Integer.MIN_VALUE)中的Integer.MIN_VALUE,不知道什么意思
值为 231-1 的常量,它表示 int 类型能够表示的最大值。
static int MIN_VALUE
值为 -231 的常量,它表示 int 类型能够表示的最小值。
我的意思是在本代码中desktopPane.add(backLabel,new Integer(Integer.MIN_VALUE)); 实现的效果是什么?
desktopPane.add(backLabel,new Integer(Integer.MIN_VALUE));
表示backLabel永远是desktopPane这个容器的最后一个组件,
也就是说,backLabel永远在desktopPane的最底层
Adds the specified component to this container at the given position. This is a convenience method for addImpl.
Note: If a component has been added to a container that has been displayed, validate must be called on that container to display the new component. If multiple components are being added, you can improve efficiency by calling validate only once, after all the components have been added.再查看:
addImpl
remove
validate
javax.swing.JComponent.revalidate()
参数:
comp the component to be added
index the position at which to insert the component, or -1 to append the component to the end
返回:
the component comp
抛出:
NullPointerException - if comp is null
IllegalArgumentException - if index is invalid (see addImpl for details)
int类型的边界值
所以最小数是-2147483648