⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 buttondemo.java

📁 主要为一个空间信息管理系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	// verticaly glue fills out the rest of the box	p1.add(Box.createVerticalGlue());	radioButtonPanel.add(Box.createRigidArea(HGAP10));	currentControls = radiobuttons;	radioButtonPanel.add(createControls());    }    public void addCheckBoxes() {	tab.addTab(getString("ButtonDemo.checkboxes"), checkboxPanel);	checkboxPanel.setLayout(new BoxLayout(checkboxPanel, BoxLayout.X_AXIS));        checkboxPanel.setBorder(border5);	JPanel p1 = createVerticalPanel(true);	p1.setAlignmentY(TOP_ALIGNMENT);	checkboxPanel.add(p1);	// Text Radio Buttons	JPanel p2 = createHorizontalPanel(false);	p1.add(p2);	p2.setBorder(new CompoundBorder(                      new TitledBorder(			null, getString("ButtonDemo.textcheckboxes"),			TitledBorder.LEFT, TitledBorder.TOP), border5)	);	checkboxes.add(p2.add(new JCheckBox(getString("ButtonDemo.check1"))));	p2.add(Box.createRigidArea(HGAP10));	checkboxes.add(p2.add(new JCheckBox(getString("ButtonDemo.check2"))));	p2.add(Box.createRigidArea(HGAP10));	checkboxes.add(p2.add(new JCheckBox(getString("ButtonDemo.check3"))));	// Image Radio Buttons	p1.add(Box.createRigidArea(VGAP30));	JPanel p3 = createHorizontalPanel(false);	p1.add(p3);	p3.setLayout(new BoxLayout(p3, BoxLayout.X_AXIS));	p3.setBorder(new TitledBorder(null, getString("ButtonDemo.imagecheckboxes"),					 TitledBorder.LEFT, TitledBorder.TOP));	// image checkbox 1	String description = getString("ButtonDemo.customcheck");	String text = getString("ButtonDemo.check1");	check = new JCheckBox(text, createImageIcon("buttons/cb.gif", description));	check.setRolloverIcon(createImageIcon("buttons/cbr.gif", description));	check.setRolloverSelectedIcon(createImageIcon("buttons/cbrs.gif", description));	check.setSelectedIcon(createImageIcon("buttons/cbs.gif", description));	check.setMargin(new Insets(0,0,0,0));	p3.add(check);	checkboxes.add(check);	p3.add(Box.createRigidArea(HGAP20));	// image checkbox 2	text = getString("ButtonDemo.check2");	check = new JCheckBox(text, createImageIcon("buttons/cb.gif", description));	check.setRolloverIcon(createImageIcon("buttons/cbr.gif", description));	check.setRolloverSelectedIcon(createImageIcon("buttons/cbrs.gif", description));	check.setSelectedIcon(createImageIcon("buttons/cbs.gif", description));	check.setMargin(new Insets(0,0,0,0));	p3.add(check);	checkboxes.add(check);	p3.add(Box.createRigidArea(HGAP20));	// image checkbox 3	text = getString("ButtonDemo.check3");	check = new JCheckBox(text, createImageIcon("buttons/cb.gif", description));	check.setRolloverIcon(createImageIcon("buttons/cbr.gif", description));	check.setRolloverSelectedIcon(createImageIcon("buttons/cbrs.gif", description));	check.setSelectedIcon(createImageIcon("buttons/cbs.gif", description));	check.setMargin(new Insets(0,0,0,0));	p3.add(check);	checkboxes.add(check);	// verticaly glue fills out the rest of the box	p1.add(Box.createVerticalGlue());	checkboxPanel.add(Box.createRigidArea(HGAP10));	currentControls = checkboxes;	checkboxPanel.add(createControls());    }    public void addToggleButtons() {	tab.addTab(getString("ButtonDemo.togglebuttons"), toggleButtonPanel);    }    public JPanel createControls() {        JPanel controls = new JPanel() {            public Dimension getMaximumSize() {                return new Dimension(300, super.getMaximumSize().height);            }        };        controls.setLayout(new BoxLayout(controls, BoxLayout.Y_AXIS));        controls.setAlignmentY(TOP_ALIGNMENT);        controls.setAlignmentX(LEFT_ALIGNMENT);        JPanel buttonControls = createHorizontalPanel(true);        buttonControls.setAlignmentY(TOP_ALIGNMENT);        buttonControls.setAlignmentX(LEFT_ALIGNMENT);        JPanel leftColumn = createVerticalPanel(false);        leftColumn.setAlignmentX(LEFT_ALIGNMENT);        leftColumn.setAlignmentY(TOP_ALIGNMENT);        JPanel rightColumn = new LayoutControlPanel(this);        buttonControls.add(leftColumn);        buttonControls.add(Box.createRigidArea(HGAP20));        buttonControls.add(rightColumn);        buttonControls.add(Box.createRigidArea(HGAP20));        controls.add(buttonControls);	createListeners();        // Display Options        JLabel l = new JLabel("Display Options:");        leftColumn.add(l);        JCheckBox bordered = new JCheckBox("Paint Border");        bordered.setToolTipText("Click here to turn border painting on or off.");        bordered.setMnemonic('b');	if (currentControls == buttons) {	        bordered.setSelected(true);	}        bordered.addItemListener(buttonDisplayListener);        leftColumn.add(bordered);        JCheckBox focused = new JCheckBox("Paint Focus");        focused.setToolTipText("Click here to turn focus painting on or off.");        focused.setMnemonic('f');        focused.setSelected(true);        focused.addItemListener(buttonDisplayListener);        leftColumn.add(focused);        JCheckBox enabled = new JCheckBox("Enabled");        enabled.setToolTipText("Click here to enable or disable the buttons.");        enabled.setSelected(true);        enabled.addItemListener(buttonDisplayListener);        enabled.setMnemonic('e');        leftColumn.add(enabled);        JCheckBox filled = new JCheckBox("Content Filled");        filled.setToolTipText("Click here to control the filling of the content area.");        filled.setSelected(true);        filled.addItemListener(buttonDisplayListener);        filled.setMnemonic('i');        leftColumn.add(filled);        leftColumn.add(Box.createRigidArea(VGAP20));        l = new JLabel("Pad Amount:");        leftColumn.add(l);        ButtonGroup group = new ButtonGroup();        JRadioButton defaultPad = new JRadioButton("Default");        defaultPad.setToolTipText("Uses the default padding between the border and label.");        defaultPad.setMnemonic('d');        defaultPad.addItemListener(buttonPadListener);        group.add(defaultPad);        defaultPad.setSelected(true);        leftColumn.add(defaultPad);        JRadioButton zeroPad = new JRadioButton("0");        zeroPad.setToolTipText("Uses no padding between the border and label.");        zeroPad.addItemListener(buttonPadListener);        zeroPad.setMnemonic('0');        group.add(zeroPad);        leftColumn.add(zeroPad);        JRadioButton tenPad = new JRadioButton("10");        tenPad.setMnemonic('1');        tenPad.setToolTipText("Uses a 10 pixel pad between the border and label.");        tenPad.addItemListener(buttonPadListener);        group.add(tenPad);        leftColumn.add(tenPad);        leftColumn.add(Box.createRigidArea(VGAP20));	return controls;    }    public void createListeners() {	buttonDisplayListener = new ItemListener() {		Component c;		AbstractButton b;		public void itemStateChanged(ItemEvent e) {		    JCheckBox cb = (JCheckBox) e.getSource();		    if(cb.getText().equals("Enabled")) {			for(int i = 0; i < currentControls.size(); i++) {			    c = (Component) currentControls.elementAt(i);			    c.setEnabled(cb.isSelected());			    c.invalidate();			}		    } else if(cb.getText().equals("Paint Border")) {			c = (Component) currentControls.elementAt(0);			if(c instanceof AbstractButton) {			    for(int i = 0; i < currentControls.size(); i++) {				b = (AbstractButton) currentControls.elementAt(i);				b.setBorderPainted(cb.isSelected());				b.invalidate();			    }			}		    } else if(cb.getText().equals("Paint Focus")) {			c = (Component) currentControls.elementAt(0);			if(c instanceof AbstractButton) {			    for(int i = 0; i < currentControls.size(); i++) {				b = (AbstractButton) currentControls.elementAt(i);				b.setFocusPainted(cb.isSelected());				b.invalidate();			    }			}		    } else if(cb.getText().equals("Content Filled")) {			c = (Component) currentControls.elementAt(0);			if(c instanceof AbstractButton) {			    for(int i = 0; i < currentControls.size(); i++) {				b = (AbstractButton) currentControls.elementAt(i);				b.setContentAreaFilled(cb.isSelected());				b.invalidate();			    }			}		    }		    invalidate();		    validate();		    repaint();		}	};	buttonPadListener = new ItemListener() {		Component c;		AbstractButton b;		public void itemStateChanged(ItemEvent e) {		    // *** pad = 0		    int pad = -1;		    JRadioButton rb = (JRadioButton) e.getSource();		    if(rb.getText().equals("0") && rb.isSelected()) {			pad = 0;		    } else if(rb.getText().equals("10") && rb.isSelected()) {			pad = 10;		    }		    for(int i = 0; i < currentControls.size(); i++) {			b = (AbstractButton) currentControls.elementAt(i);			if(pad == -1) {			    b.setMargin(null);			} else if(pad == 0) {			    b.setMargin(insets0);			} else {			    b.setMargin(insets10);			}		    }		    invalidate();		    validate();		    repaint();		}	};    }    public void stateChanged(ChangeEvent e) {	SingleSelectionModel model = (SingleSelectionModel) e.getSource();	if(model.getSelectedIndex() == 0) {	    currentControls = buttons;	} else if(model.getSelectedIndex() == 1) {	    currentControls = radiobuttons;	} else if(model.getSelectedIndex() == 2) {	    currentControls = checkboxes;	} else {	    currentControls = togglebuttons;	}    }    public Vector getCurrentControls() {	return currentControls;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -