JFrame frame2 = new JFrame("Tauler Joc"); JPanel panell = new JPanel(); ImageIcon icon = new ImageIcon("king.jpg"); JButton jb= new JButton(); jb.setBounds(200,200,700,700); panell.add(jb); // Set image to size of JButton... int offset = jb.getInsets().left; jb.setIcon(resizeIcon(icon, jb.getWidth() - offset, jb.getHeight() - offset)); frame2.add(panell); frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
protected Rectangle rectangleForCurrentValue() { int width = comboBox.getWidth(); int height = comboBox.getHeight(); Insets insets = getInsets(); int buttonSize = height - (insets.top + insets.bottom); if (arrowButton != null) { if (arrowButton instanceof PgsComboBoxButtonUI) { Icon icon = ((PgsComboBoxButtonUI) arrowButton).getComboIcon(); Insets buttonInsets = arrowButton.getInsets(); buttonSize = icon.getIconWidth() + buttonInsets.left + buttonInsets.right; } else { buttonSize = arrowButton.getWidth(); } } if(PgsUtils.isLeftToRight(comboBox)) { return new Rectangle(insets.left+2, insets.top+1, width - (insets.left + insets.right + buttonSize + 4), height - (insets.top + insets.bottom)-2); } else { return new Rectangle(insets.left + buttonSize + 2, insets.top+1, width - (insets.left + insets.right + buttonSize + 4), height - (insets.top + insets.bottom)-2); } }
@Override public void actionPerformed(ActionEvent e) { if (!comboBox.isEditable()) { flasherVisible = !flasherVisible; if (!flasherVisible) { Graphics g = arrowButton.getGraphics(); if (g != null) { g.setColor(usingOcean ? UIManager.getColor("Button.focus") : arrowButton.getBackground()); Insets insets = arrowButton.getInsets(); int width = arrowButton.getWidth() - (insets.left + insets.right); int height = arrowButton.getHeight() - (insets.top + insets.bottom); if (height > 0 && width > 0) { int left = insets.left; int top = insets.top; g.drawRect( left - 1, top - 1, width + 3, height + 1 ); } } } else { arrowButton.repaint(); } } } }
private void refreshUI() { if (notification.isClosed()) { closeActionListener.actionPerformed(null); } setVisible(!notification.isHidden()); nameLabel.setText(notification.getName()); // set the subtext color to red if the description contains the word "error" subTextLabel.setText(notification.getDescription()); subTextLabel.setForeground(notification.getDescription().toLowerCase().contains("error") ? subTextErrorColor : subTextNormalColor); closeButton.setVisible(notification.canHide()); ViewUtil.ellipsizeLabel(nameLabel, middleWidth - 2 * innerinsets); ViewUtil.ellipsizeLabel(subTextLabel, middleWidth - 2 * innerinsets); if (notification.isShowsProgress()) { progressIndifinite.setVisible(notification.isIndeterminateProgress()); progress.setVisible(!notification.isIndeterminateProgress()); progress.setValue((int) (notification.getProgress() * 100)); } else { progressIndifinite.setVisible(false); progress.setVisible(false); } if (notification.getAction() != null) { actionButton.removeActionListener(notification.getAction()); actionButton.addActionListener(notification.getAction()); actionButton.setText(ViewUtil.ellipsize(notification.getActionName(), rightWidth - innerinsets - actionButton.getInsets().left - actionButton.getInsets().right)); actionButton.setVisible(true); } this.updateUI(); }
public void layoutComboBox(Container parent, MetalComboBoxLayoutManager manager) { if (arrowButton != null) { if (arrowButton instanceof PgsComboBoxButtonUI) { Icon icon = ((PgsComboBoxButtonUI) arrowButton).getComboIcon(); Insets buttonInsets = arrowButton.getInsets(); Insets insets = comboBox.getInsets(); int buttonWidth = icon.getIconWidth() + buttonInsets.left + buttonInsets.right; arrowButton.setBounds( PgsUtils.isLeftToRight(comboBox) ? (comboBox.getWidth() - insets.right - buttonWidth) : insets.left+2, insets.top + 2, buttonWidth - 2, comboBox.getHeight() - insets.top - insets.bottom - 4); } else { Insets insets = comboBox.getInsets(); int width = comboBox.getWidth(); int height = comboBox.getHeight(); arrowButton.setBounds( insets.left, insets.top, width - (insets.left + insets.right), height - (insets.top + insets.bottom)); } } if (editor != null) { Rectangle cvb = rectangleForCurrentValue(); editor.setBounds(cvb); } }
if (arrowButton instanceof BasicJideComboBoxButton) { Icon icon = ((BasicJideComboBoxButton) arrowButton).getComboIcon(); Insets buttonInsets = arrowButton.getInsets(); Insets insets = comboBox.getInsets(); int buttonWidth = icon.getIconWidth() + buttonInsets.left +