private void asociarEventosBotones(JPanel panel) { for (int i = 0; i < panel.getComponents().length; i++) { JButton boton = (JButton) panel.getComponents()[i]; boton.setActionCommand(String.valueOf(i)); boton.addActionListener(listener); } }
/** * Switches views based on the passed enum. * * @param v the View to switch to * @param o A BattleField if switching to BattleView. */ public void changeView(Views v, Object o) { switch (v) { case PREVIOUS: CardLayout cl = (CardLayout) body.getLayout(); JPanel temp = currentPanel; panels.pop(); currentPanel = panels.peek(); cl.show(body, currentPanel.toString()); cl.removeLayoutComponent(temp); break; case BATTLE: currentPanel = new BattleView(this, (BattleField) o); panels.push(currentPanel); body.add(currentPanel, v.name()); CardLayout cl1 = (CardLayout) body.getLayout(); cl1.show(body, v.name()); for (Component c : body.getComponents()) { if (c == currentPanel) { c.requestFocusInWindow(); } } break; case TITLE: currentPanel = new TitleView(this); panels.push(currentPanel); body.add(currentPanel, v.name()); CardLayout cl2 = (CardLayout) body.getLayout(); cl2.show(body, v.name()); break; default: // Do nothing } }
private void enableAuto(boolean enable) { Component[] comps = _controlPanel.getComponents(); if (enable) { int idx = 0; while (idx < comps.length) { if (comps[idx].equals(_manualPanel)) { break; } idx++; } _controlPanel.remove(idx); _autoRunPanel = makeAutoRunPanel( jmri.InstanceManager.getDefault(SignalSpeedMap.class).getInterpretation()); _controlPanel.add(_autoRunPanel, idx); } else { int idx = 0; while (idx < comps.length) { if (comps[idx].equals(_autoRunPanel)) { break; } idx++; } _controlPanel.remove(idx); _manualPanel = makeTrainIdPanel(null); _controlPanel.add(_manualPanel, idx); } pack(); }
/** Row striping */ private void updateColors() { for (int i = 0; i < pnlItem.getComponentCount(); i++) { pnlItem.getComponents()[i].setBackground((i % 2 == 0) ? Constants.ALT_COLOR : null); } repaint(); }
public static void deSelect(JPanel layer) { Component[] components = layer.getComponents(); int i = 0; while (i < components.length) { if (components[i].getClass().getName().equals("javax.swing.JLabel")) { if (components[i].getBackground().equals(SELECT)) { JLabel temp = (JLabel) components[i]; temp.setOpaque(false); components[i].setBackground(DESELECT); } } if (components[i].getClass().getName().equals("Display.TextBox")) { if (components[i].getBackground().equals(SELECT)) { components[i].setBackground(DESELECT); } } // If panel is selected, de-select all components nested on panel if (components[i].getClass().getName().equals("javax.swing.JPanel")) { if (components[i].getBackground().equals(SELECT)) { components[i].setBackground(DESELECT); } deSelect((JPanel) components[i]); } i++; } }
private void modificarPanel(JPanel panel, boolean habilitar) { Component[] botones = panel.getComponents(); for (int i = 0; i < botones.length; i++) { JButton boton = (JButton) botones[i]; boton.setEnabled(habilitar); } }
private void makeGUIReadOnly() { for (Component c : options_.getComponents()) c.setEnabled(false); occurred_.setEnabled(false); description_.setEditable(false); if (line_item_form_ != null) line_item_form_.setReadOnly(true); setBottomComponent(new JLabel("<html><i>Select an entry to view details</i></html>")); this.setDividerLocation(); }
public void setValues() { // Update all field values in the tabs: int count = main.getComponentCount(); Component[] comps = main.getComponents(); for (int i = 0; i < count; i++) { ((PrefsTab) comps[i]).setValues(); } }
public Collection<String> getSelectedTracks() { List<String> selectedTracks = new ArrayList<String>(); for (Component c : listPanel.getComponents()) { if (c instanceof JCheckBox && ((JCheckBox) c).isSelected()) { selectedTracks.add(((JCheckBox) c).getText()); } } return selectedTracks; }
/** * method to check whether a mouse click was over an icon * * @param p * @return */ private Component getImageLabel(Point p) { Rectangle r1 = activePanel.getBounds(); Rectangle r; Component[] c = activePanel.getComponents(); for (int j = 0; j < c.length; j++) { r = c[j].getBounds(); if (r.contains(p.x - r1.x, p.y - r1.y)) return c[j]; } return null; }
public static void limparCampos(JPanel jPanel) { Component[] components = jPanel.getComponents(); JTextField jTextField = null; for (int i = 0; i < components.length; i++) { if (components[i] instanceof JTextField) { jTextField = (JTextField) components[i]; jTextField.setText(""); } } }
/** Reloads icon. */ public void loadSkin() { if (messagePanel != null) { for (Component component : messagePanel.getComponents()) { if (component instanceof ImageCanvas) { ImageCanvas cmp = (ImageCanvas) component; cmp.setImage(ImageLoader.getImage(ImageLoader.RENAME_DIALOG_ICON)); } } } }
private void backJButtonActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_backJButtonActionPerformed userProcessContainer.remove(this); Component[] componentArray = userProcessContainer.getComponents(); Component component = componentArray[componentArray.length - 1]; PersonWorkAreaJPanel dwjp = (PersonWorkAreaJPanel) component; dwjp.populateTable(); CardLayout layout = (CardLayout) userProcessContainer.getLayout(); layout.previous(userProcessContainer); } // GEN-LAST:event_backJButtonActionPerformed
public String[] getRight() { List<String> tmp = new ArrayList<>(); Component[] components = lowerPanel.getComponents(); for (int i = 0; i < components.length; i++) { Component component = components[i]; if (component instanceof ComparedValuePanel) { tmp.add(((ComparedValuePanel) component).textField_1.getText()); } } return tmp.toArray(new String[0]); }
public ArrayList<Treasure> getSelectedTreasures(JPanel aPanel) { TreasureView treasureView; ArrayList<Treasure> selected = new ArrayList(); for (Component treasure : aPanel.getComponents()) { treasureView = (TreasureView) treasure; if (treasureView.isSelected()) selected.add(treasureView.getTreasure()); } return selected; }
private void rescaling() // method used to rescale UI { scalingfactor = Start.interfaceScalingFactor; // System.out.println("getPreferredSize().width=" + getPreferredSize().width); // System.out.println("getPreferredSize().height=" + getPreferredSize().height); int width = (int) (getPreferredSize().width * scalingfactor); int height = (int) (getPreferredSize().height * scalingfactor); // System.out.println("MainFrame scalingfactor=" + scalingfactor + " width=" + width + " // height=" + height); setPreferredSize( new Dimension( (int) (getPreferredSize().width * scalingfactor), (int) (getPreferredSize().height * scalingfactor))); setBounds(0, 0, (int) (1680 * scalingfactor), (int) (1050 * scalingfactor)); for (Component comp : this.getComponents()) { comp.setPreferredSize( new Dimension( (int) (comp.getPreferredSize().width * scalingfactor), (int) (comp.getPreferredSize().height * scalingfactor))); comp.setBounds( (int) (comp.getX() * scalingfactor), (int) (comp.getY() * scalingfactor), (int) (comp.getWidth() * scalingfactor), (int) (comp.getHeight() * scalingfactor)); // comp=rescaleComponent(comp); rescaleComponent(comp); if (comp instanceof JMenuBar) { JMenuBar jM = (JMenuBar) comp; for (Component lComp : jM.getComponents()) { rescaleComponent(lComp); } } if (comp instanceof JPanel) { JPanel jP = (JPanel) comp; for (Component lComp : jP.getComponents()) { rescaleComponent(lComp); } } if (comp instanceof JScrollPane) { JScrollPane jSp = (JScrollPane) comp; for (Component lComp : jSp.getComponents()) { rescaleComponent(lComp); } } } repaint(); revalidate(); }
private void resizeWizardPage() { logger.trace("resizeWizardPage() - start"); int h = contentPanel.getHeight(); int w = contentPanel.getWidth(); Dimension size = new Dimension(w, h); for (Component wp : contentPanel.getComponents()) { wp.setSize(size); } logger.trace("resizeWizardPage() - end"); }
public static void removePanel() { bottom.remove(bottom.getComponents()[bottom.getComponentCount() - 1]); if (bottom.getComponentCount() == 1) {} // JPanel p = null; // for (Component comp : bottom.getComponents()) { // if (comp.getName().equals(name)) { // p = (JPanel) comp; // } // } // bottom.remove(p); }
private void setPanelBackGroundForeGround( JPanel panel, Color selectionBackground, Color selectionForeground, boolean labelBold) { panel.setBackground(selectionBackground); panel.setForeground(selectionForeground); for (int i = 0; i < panel.getComponents().length; i++) { panel.getComponent(i).setBackground(selectionBackground); panel.getComponent(i).setForeground(selectionForeground); if (panel.getComponent(i) instanceof JLabel && labelBold) { ((JLabel) panel.getComponent(i)) .setText("<html><b>" + ((JLabel) panel.getComponent(i)).getText() + "</html></b>"); } } }
private void updateFontSizeForPanel(JPanel panel) { int font_size = (int) (panel.getWidth() * ENTRY_FONT_SIZE); if (font_size > MAX_ENTRY_FONT_SIZE) { font_size = MAX_ENTRY_FONT_SIZE; } JLabel temp = new JLabel(); Font font = new Font(temp.getFont().getFontName(), Font.BOLD, font_size); for (Component comp : panel.getComponents()) { comp.setFont(font); } panel.revalidate(); }
public void actionPerformed(ActionEvent e) { String command = e.getActionCommand(); if (command.startsWith("start")) { discard_all = true; } else if (command.startsWith("stop")) { discard_all = false; Component[] comps = checkboxes.getComponents(); for (Component c : comps) { if (c instanceof JCheckBox) { ((JCheckBox) c).setSelected(false); } } ignoredMembers.clear(); } }
private void setMultiTextbox(boolean b) { Component[] components = lowerPanel.getComponents(); int idx = 0; for (int i = 0; i < components.length; i++) { Component component = components[i]; if (component instanceof ComparedValuePanel) { ((ComparedValuePanel) component).setButtonVisivle(b); if (!b && idx != 0) { lowerPanel.remove(component); } idx++; } } checkBox_3.setVisible(b); }
public void addChatRoomButton(ChatRoomButton button) { buttonPanel.add(button); Component[] comps = buttonPanel.getComponents(); final int no = comps != null ? comps.length : 0; final List<Component> buttons = new ArrayList<Component>(); for (int i = 0; i < no; i++) { try { Component component = comps[i]; if (component instanceof JButton) buttons.add(component); } catch (NullPointerException e) { } } GraphicUtils.makeSameSize((JComponent[]) buttons.toArray(new JComponent[buttons.size()])); }
public void updatePanel(int interp) { if (_controlPanel == null) { return; } // find position of panel java.awt.Component[] list = _controlPanel.getComponents(); int i = 0; while (i < list.length && !list[i].equals(_autoRunPanel)) { i++; } if (i < list.length) { _controlPanel.remove(_autoRunPanel); _autoRunPanel = makeAutoRunPanel(interp); _controlPanel.add(_autoRunPanel, i); pack(); } }
public boolean save() { for (Object component : genericTagPropertiesEditPanel.getComponents()) { if (component instanceof GenericTagEditor) { try { ((GenericTagEditor) component).validateValue(); ((GenericTagEditor) component).save(); } catch (IllegalArgumentException iex) { return false; } } } SWF swf = tag.getSwf(); assignTag(tag, editedTag); tag.setModified(true); tag.setSwf(swf); setTagText(tag); return true; }
/** * Calculates the area in which this panel actually paints stuff. * * @param g the graphics context that will paint the panel, not <code>null</code> * @return the boundaries, never <code>null</code> */ public Rectangle getVisibleBoundaries(Graphics g) { Rectangle result = null; for (GraphPaintable paintable : paintables) { Rectangle boundaries = paintable.getVisibleBoundaries(g); result = union(result, boundaries); } for (Component child : canvas.getComponents()) { Rectangle boundaries = child.getBounds(); result = union(result, boundaries); } if (result == null) { result = new Rectangle(0, 0, 50, 50); } return result; }
void handleView(Collection<Address> mbrs) { checkboxes.removeAll(); for (final Address addr : mbrs) { final MyCheckBox box = new MyCheckBox("discard traffic from " + addr, addr); box.addActionListener( e -> { if (box.isSelected()) ignoredMembers.add(addr); else ignoredMembers.remove(addr); }); checkboxes.add(box); } for (Component comp : checkboxes.getComponents()) { MyCheckBox box = (MyCheckBox) comp; if (ignoredMembers.contains(box.mbr)) box.setSelected(true); } pack(); }
/** * @see Método que verifica se os elementos do JPanel são diferentes de null, usado para verificar * se os campos estão preenchidos pelo usuário. * @param panel * @return false caso pelo menos um componente possuir getText() == null. */ public boolean validarCampos(JPanel panel) { Component componentes[] = panel.getComponents(); boolean erro = true; for (Component c : componentes) { if (c instanceof JTextField) { if (((JTextField) c).isEnabled()) { if (((JTextField) c).getText().trim().equals("")) { ((JTextField) c).setBorder(new LineBorder(Color.RED)); erro = false; } else { ((JTextField) c).setBorder(new LineBorder(Color.LIGHT_GRAY)); } } else { ((JTextField) c).setBorder(new LineBorder(Color.LIGHT_GRAY)); } } } return erro; }
private JPanel getMixerOptionsPanel() { if (mixerOptionsPanel == null) { mixerOptionsPanel = new JPanel(); mixerOptionsPanel.setBorder( BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Mixer")); mixerOptionsPanel.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.anchor = GridBagConstraints.NORTHWEST; c.fill = GridBagConstraints.NONE; c.weightx = 1; c.insets = new Insets(8, 4, 0, 0); mixerOptionsPanel.add(new JLabel("Select mixer:"), c); c.gridy = 1; mixerOptionsPanel.add(getMixerComboBox(), c); c.gridy = 2; mixerOptionsPanel.add(getMixerDefaultButton(), c); c.insets = new Insets(16, 4, 0, 0); c.gridy = 3; mixerOptionsPanel.add(new JLabel("Enable mixer features:"), c); c.insets = new Insets(6, 0, 0, 0); c.gridy = 4; mixerOptionsPanel.add(getEnableMixerVolumeCheckBox(), c); c.insets = new Insets(0, 0, 0, 0); c.gridy = 5; mixerOptionsPanel.add(getEnableMixerPanCheckBox(), c); if (AudioSystem.getMixerInfo().length == 0) { for (Component child : mixerOptionsPanel.getComponents()) { child.setEnabled(false); } } } return mixerOptionsPanel; }
/** Creating buttons with coordinates and action listeners */ private MyButton createButton() { // The new buttons counters - // will be translates to coordinates if (counterX >= size) { counterX = 0; counterY++; } MyButton button = new MyButton(); // set buttons coordinates button.x = counterX++; button.y = counterY; // The buttons properties adjustment button.setPreferredSize(new Dimension(50, 50)); button.setFont(new Font("Dialog", Font.PLAIN, 72)); // Action listener button.addActionListener( e -> { game.move(new Move(button.x, button.y)); game.isGameOver(); button.setText(game.getField()[button.x][button.y] > 0 ? "X" : "O"); button.setEnabled(false); statusStr.setText(game.getState().toString()); // If the game is over // disable all unselected buttons if (game.getState().equals(GameState.X_WINS) || game.getState().equals(GameState.O_WINS)) { for (Component b : gameField.getComponents()) { b.setEnabled(false); } } }); // System.out.println("button " + button.x + " " + button.y); return button; }