java点点滴滴...
时间:2010-08-07 来源:haizilin
(1)DefaultBoundedRangeModel model = new DefaultBoundedRangeModel();
定义对象时就调用默认的构造函数实例化对象。
(2)public class ScrollBarExample extends JPanel {
public ScrollBarExample() {
super(true);
...............
super作用:
javax.swing.JPanel.JPanel(boolean isDoubleBuffered)
Creates a new JPanel with FlowLayout and the specified buffering strategy. If isDoubleBuffered is true,the JPanel will use a double buffer. 参数:
isDoubleBuffered a boolean, true for double-buffering, which uses additional memory space to achieve fast, flicker-free updates;
(3)label.setText(" New Value is " + e.getValue() + " ");
void javax.swing.JLabel.setText(String text)
Defines the single line of text this component will display. If the value of text is null or empty string, nothing is displayed.The default value of this property is null.This is a JavaBeans bound property.
参数:
text另请参阅:
setVerticalTextPosition
setHorizontalTextPositionsetIcon
@beaninfo
preferred: true bound: true attribute: visualUpdate true description: Defines the single line of text this component will display.
(4) public class ScrollBarExample extends JPanel { //extends的是JPanel
JLabel label;
public ScrollBarExample() {
..................
}
public static void main(String s[]) {
JFrame frame = new JFrame("Scroll Bar Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(new ScrollBarExample());//通过这句与上面的构造函数联系起来
frame.setSize(200,200);
frame.setVisible(true);
}
}
(5) JTextArea对象可以直接add()入JFrame中;而JTextField必须放于JPanel中,不能直接add()入JFrame。
(6) JFrame frame=new JFrame();
...........
frame.pack();
frame.pack()方法:
依据放置的组件设定窗口的大小,使之正好能容纳所放置的所有组件,若pack()和setSize()同时出现于程序中,则放在后面的那个方法起作用,前面的方法被覆盖了 ,而不起作用!
(7) frame.setContentPane(p); 等价于 frame.getContentPane().add(p);(此时两者皆是默认的CERTER)
区别是f.setContentPane(p)只能是默认的位置:CENTER,而不能自由的调整