Java Code Examples for javax.swing.JToggleButton#setBounds()

The following examples show how to use javax.swing.JToggleButton#setBounds() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SwitchController.java    From Ardulink-2 with Apache License 2.0 5 votes vote down vote up
/**
 * Create the panel.
 */
public SwitchController() {
	setPreferredSize(new Dimension(125, 75));
	setLayout(null);
	pinComboBoxModel = new IntMinMaxModel(0, 40).withSelectedItem(3);
	JComboBox pinComboBox = new JComboBox(pinComboBoxModel);
	pinComboBox.setBounds(66, 11, 47, 22);
	add(pinComboBox);
	
	JLabel label = new JLabel("Power Pin:");
	label.setFont(new Font("SansSerif", Font.PLAIN, 11));
	label.setBounds(10, 15, 59, 14);
	add(label);
	
	switchToggleButton = new JToggleButton("Off");
	switchToggleButton.addItemListener(new ItemListener() {
		@Override
		public void itemStateChanged(ItemEvent e) {
			int pin = pinComboBoxModel.getSelectedItem().intValue();
			if(e.getStateChange() == ItemEvent.SELECTED) {
				switchToggleButton.setText("On");
				link.sendPowerPinSwitch(pin, true);
			} else if(e.getStateChange() == ItemEvent.DESELECTED) {
				switchToggleButton.setText("Off");
				link.sendPowerPinSwitch(pin, false);
			}
		}
	});
	switchToggleButton.setBounds(10, 38, 103, 23);
	add(switchToggleButton);
}
 
Example 2
Source File: SwitchController.java    From Ardulink-1 with Apache License 2.0 5 votes vote down vote up
/**
 * Create the panel.
 */
public SwitchController() {
	setPreferredSize(new Dimension(125, 75));
	setLayout(null);
	pinComboBoxModel = new IntMinMaxModel(0, 40).withSelectedItem(3);
	JComboBox pinComboBox = new JComboBox(pinComboBoxModel);
	pinComboBox.setBounds(66, 11, 47, 22);
	add(pinComboBox);
	
	JLabel label = new JLabel("Power Pin:");
	label.setFont(new Font("SansSerif", Font.PLAIN, 11));
	label.setBounds(10, 15, 59, 14);
	add(label);
	
	switchToggleButton = new JToggleButton("Off");
	switchToggleButton.addItemListener(new ItemListener() {
		public void itemStateChanged(ItemEvent e) {
			int pin = pinComboBoxModel.getSelectedItem().intValue();
			if(e.getStateChange() == ItemEvent.SELECTED) {
				switchToggleButton.setText("On");
				link.sendPowerPinSwitch(pin, IProtocol.POWER_HIGH);
			} else if(e.getStateChange() == ItemEvent.DESELECTED) {
				switchToggleButton.setText("Off");
				link.sendPowerPinSwitch(pin, IProtocol.POWER_LOW);
			}
		}
	});
	switchToggleButton.setBounds(10, 38, 103, 23);
	add(switchToggleButton);
}
 
Example 3
Source File: TesteComponentes.java    From dctb-utfpr-2018-1 with Apache License 2.0 4 votes vote down vote up
public void TesteComponente(){
    janela.setVisible(true);
    janela.setSize(DIMENSOES);
    janela.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
    JScrollPane teste1 = new JScrollPane(painel);
    teste1.setBounds(1, 2, 150, 200);
    
    JButton teste2 = new JButton("Aperte");
    teste2.setBounds(210, 2, 100, 100);
    
    JToggleButton teste3 = new JToggleButton("Toggle");
    teste3.setBounds(320, 2, 100, 100);
    
    JCheckBox teste4 = new JCheckBox("Teste");
    teste4.setBounds(430, 2, 100, 100);
    
    JRadioButton teste5 = new JRadioButton("Teste2");
    teste5.setBounds(540, 2, 100, 100);
    
    JTextField teste6 = new JTextField();
    teste6.setToolTipText("Seu Nome");
    teste6.setBounds(1, 205, 200, 50);
    
    String[] numeros = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"};
    JList teste7 = new JList(numeros);
    JScrollPane teste7_2 = new JScrollPane(teste7);
    teste7_2.setBounds(210, 205, 100, 100);
    
    String[] numeros2 = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"};
    JComboBox teste8 = new JComboBox(numeros2);
    teste8.setBounds(320, 205, 50, 50);
    
    JLabel teste9 = new JLabel();
    teste9.setText("Biografia: ");
    teste9.setBounds(1, 290, 200, 100);
    
    JTextArea teste10 = new JTextArea();
    teste10.setToolTipText("Biografia");
    teste10.setBounds(1, 350, 100, 100);
    
    teste2.addActionListener(this);
    teste3.addActionListener(this);
    teste4.addActionListener(this);
    teste5.addActionListener(this);
    
    janela.add(teste1);
    janela.add(teste2);
    janela.add(teste3);
    janela.add(teste4);
    janela.add(teste5);
    janela.add(teste6);
    janela.add(teste7);
    janela.add(teste8);
    janela.add(teste9);
    janela.add(teste10);
}
 
Example 4
Source File: PaletteUI.java    From pumpernickel with MIT License 4 votes vote down vote up
@Override
public void layoutContainer(Container parent) {
	JPalette p = (JPalette) parent;
	Color[][] paletteLayout = p.getColors();

	List<JToggleButton> cells = getCells(parent);

	Insets i = p.getInsets();

	int height = p.getHeight() - i.left - i.right;
	int width = p.getWidth() - i.top - i.bottom;

	boolean buttonStatesDirty = false;
	int y = i.top;
	for (int row = 0; row < paletteLayout.length; row++) {
		int x = i.left;
		int y2 = i.top + (row + 1) * height / paletteLayout.length;
		for (int col = 0; col < paletteLayout[0].length; col++) {
			int x2 = i.left + (col + 1) * width
					/ paletteLayout[0].length;
			if (paletteLayout[row][col] != null) {
				JToggleButton cell;
				if (cells.size() == 0) {
					cell = createCell();
					p.add(cell);
				} else {
					cell = cells.remove(0);
				}
				boolean dirtyForeground = !Objects.equals(
						cell.getForeground(), paletteLayout[row][col]);
				if (dirtyForeground) {
					cell.setForeground(paletteLayout[row][col]);
					buttonStatesDirty = true;
				}
				cell.setBounds(x, y, x2 - x, y2 - y);

				String hexName = Integer
						.toHexString(paletteLayout[row][col].getRGB());
				while (hexName.length() < 6)
					hexName = "0" + hexName;
				if (hexName.length() == 8)
					hexName = hexName.substring(2);
				hexName = "0x" + hexName.toUpperCase();

				String desc;
				if (paletteLayout[row][col] instanceof AccessibleColor) {
					AccessibleColor a = (AccessibleColor) paletteLayout[row][col];
					desc = hexName + " \""
							+ a.getName(Locale.getDefault()) + "\"";
				} else {
					desc = hexName;
				}
				cell.setToolTipText(desc);
				cell.getAccessibleContext().setAccessibleName(desc);
			}
			x = x2;
		}
		y = y2;
	}
	while (cells.size() > 0) {
		p.remove(cells.remove(0));
	}

	if (buttonStatesDirty) {
		getFields(p, true).refreshSelectedStates();
	}
}