Java Code Examples for javax.swing.JButton#setUI()

The following examples show how to use javax.swing.JButton#setUI() . 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: HelpButton.java    From pumpernickel with MIT License 6 votes vote down vote up
/**
 * This returns a <code>JButton</code> that can be used to trigger help.
 * <p>
 * Currently this is a circular button with the text "?".
 * 
 * @param actionListener
 *            the listener that is triggered when you either click the help
 *            JButton or JLink.
 * @param tooltipText
 *            the optional tooltip text for this component.
 * @return the help button
 */
public static JButton create(ActionListener actionListener,
		String tooltipText) {
	JButton helpButton = new JButton();
	QButtonUI ui = new RoundRectButtonUI();
	helpButton
			.putClientProperty(QButtonUI.PROPERTY_IS_CIRCLE, Boolean.TRUE);
	Font font = helpButton.getFont().deriveFont(Font.BOLD);
	Icon glyphIcon = new GlyphIcon(font, '?', 14, Color.black);
	helpButton.setIcon(glyphIcon);
	helpButton.setUI(ui);
	helpButton.addActionListener(actionListener);
	helpButton.setToolTipText(tooltipText);

	return helpButton;
}
 
Example 2
Source File: QComboBoxUI.java    From pumpernickel with MIT License 6 votes vote down vote up
@Override
public Dimension getMinimumSize(JComponent c) {
	Dimension d = super.getMinimumSize(c);

	// if it's not a large variance: use the height of
	// a button. This way our combobox and buttons are a uniform
	// height when they're in the same row.

	if (buttonMinSize == null) {
		JButton button = new JButton("X");
		button.setUI(buttonUI);
		buttonMinSize = button.getPreferredSize();
	}
	int distance = Math.abs(d.height - buttonMinSize.height);
	if (distance < 5)
		d.height = Math.min(d.height, buttonMinSize.height);
	return d;
}
 
Example 3
Source File: EditPreferences.java    From iBioSim with Apache License 2.0 6 votes vote down vote up
private static JButton createColorButton(Color color) {
	JButton colorButton = new JButton();
	colorButton.setPreferredSize(new Dimension(30, 20));
	colorButton.setBorder(BorderFactory.createLineBorder(Color.darkGray));
	colorButton.setBackground(color);
	colorButton.setForeground(color);
	colorButton.setUI(new MetalButtonUI());
	//colorButton.setActionCommand("" + i);
	colorButton.addActionListener(new ActionListener() {
		@Override
		public void actionPerformed(ActionEvent e) {
			//int i = Integer.parseInt(e.getActionCommand());
			Color newColor = JColorChooser.showDialog(Gui.frame, "Choose Color", ((JButton) e.getSource()).getBackground());
			if (newColor != null) {
				((JButton) e.getSource()).setBackground(newColor);
				((JButton) e.getSource()).setForeground(newColor);
			}
		}
	});
	return colorButton;
}
 
Example 4
Source File: GroupWindow.java    From egdownloader with GNU General Public License v2.0 6 votes vote down vote up
public GroupWindow(List<File> groups, final EgDownloaderWindow mainWindow){
	super(Version.NAME + "任务组列表");
	this.mainWindow = mainWindow;
	this.setSize(300, 400);
	this.setResizable(false);
	this.setIconImage(IconManager.getIcon("group").getImage());
	this.setLocationRelativeTo(null);
	this.getContentPane().setLayout(null);
	this.setDefaultCloseOperation(mainWindow == null ? EXIT_ON_CLOSE : DISPOSE_ON_CLOSE);
	JLabel tipLabel = new AJLabel("双击选择任务组", new Color(67,44,1), 15, 15, 100, 30);
	JButton addGroupBtn = new AJButton("新建", IconManager.getIcon("add"), new OperaBtnMouseListener(this, MouseAction.CLICK, new IListenerTask() {
						public void doWork(Window window, MouseEvent e) {
							new AddGroupDialog((GroupWindow) window, mainWindow);
						}
					}) , 215, 15, 62, 30);
	addGroupBtn.setUI(AJButton.blueBtnUi);
	JList list = new GroupList(groups, this, mainWindow);
	list.setSelectedIndex(0);
	JScrollPane listPane = new JScrollPane(list);
	listPane.setBounds(new Rectangle(10, 50, 270, 300));
	listPane.setAutoscrolls(true);
	listPane.getViewport().setBackground(new Color(254,254,254));
	ComponentUtil.addComponents(this.getContentPane(), tipLabel, addGroupBtn, listPane);
	
	this.setVisible(true);
}
 
Example 5
Source File: OutlookBarMain.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
void addTab(JOutlookBar tabs, String title) {
  JPanel panel = new JPanel();
  panel.setLayout(new PercentLayout(PercentLayout.VERTICAL, 0));
  panel.setOpaque(false);

  String[] buttons = new String[] {"Inbox", "icons/outlook-inbox.gif",
    "Outbox", "icons/outlook-outbox.gif", "Drafts", "icons/outlook-inbox.gif",
    "Templates", "icons/outlook-inbox.gif", "Deleted Items",
    "icons/outlook-trash.gif",};

  for (int i = 0, c = buttons.length; i < c; i += 2) {
    JButton button = new JButton(buttons[i]);
    try {
      button.setUI((ButtonUI)Class.forName(
        (String)UIManager.get("OutlookButtonUI")).newInstance());
    } catch (Exception e) {
      e.printStackTrace();
    }
    button.setIcon(new ImageIcon(OutlookBarMain.class
      .getResource(buttons[i + 1])));
    panel.add(button);
  }

  JScrollPane scroll = tabs.makeScrollPane(panel);
  tabs.addTab("", scroll);

  // this to test the UI gets notified of changes
  int index = tabs.indexOfComponent(scroll);
  tabs.setTitleAt(index, title);
  tabs.setToolTipTextAt(index, title + " Tooltip");
}
 
Example 6
Source File: Demo.java    From Swing9patch with Apache License 2.0 5 votes vote down vote up
private void initGUI()
{
	// init components
	txtPhotoframeDialogWidth = new JTextField();
	txtPhotoframeDialogHeight = new JTextField();
	txtPhotoframeDialogWidth.setText("530");
	txtPhotoframeDialogHeight.setText("450");
	txtPhotoframeDialogWidth.setColumns(10);
	txtPhotoframeDialogHeight.setColumns(10);
	
	btnShowInFrame = new JButton("Show in new frame...");
	btnShowInFrame.setUI(new BEButtonUI().setNormalColor(BEButtonUI.NormalColor.blue));
	btnShowInFrame.setForeground(Color.white);
	btnHideTheFrame = new JButton("Hide the frame");
	btnHideTheFrame.setEnabled(false);
	
	panePhotoframe = createPhotoframe();
	panePhotoframe.add(
			new JLabel(new ImageIcon(org.jb2011.swing9patch.photoframe.Demo.class.getResource("imgs/girl.png")))
			, BorderLayout.CENTER);
	
	// init layout
	JPanel paneBtn = new JPanel(new FlowLayout(FlowLayout.CENTER));
	paneBtn.setBorder(BorderFactory.createEmptyBorder(12,0,0,0));
	paneBtn.add(new JLabel("Frame width:"));
	paneBtn.add(txtPhotoframeDialogWidth);
	paneBtn.add(new JLabel("Frame height:"));
	paneBtn.add(txtPhotoframeDialogHeight);
	paneBtn.add(btnShowInFrame);
	paneBtn.add(btnHideTheFrame);
	
	this.setBorder(BorderFactory.createEmptyBorder(12,20,10,20));
	this.add(panePhotoframe, BorderLayout.CENTER);
	this.add(paneBtn, BorderLayout.SOUTH);
	
	// drag panePhotoframe to move its parent window
	DragToMove.apply(new Component[]{panePhotoframe});
}
 
Example 7
Source File: Demo.java    From Swing9patch with Apache License 2.0 5 votes vote down vote up
private void initGUI()
{
	txtMsg = new JTextArea(5,5);
	txtPositionX = new JTextField();
	txtPositionY = new JTextField();
	txtDelay = new JTextField();
	btnShowToast = new JButton("Show toast");
	
	// init sub coms
	txtMsg.setText(
			"<html>\n" +
				"<body>\n" +
					"Hello ninepatch for JavaSE, you are <b>so cool</b>!\n" +
				"</body>\n" +
			"</html>\n");
	txtPositionX.setText("-1");
	txtPositionY.setText("-1");
	txtDelay.setText("3000");
	txtPositionX.setColumns(10);
	txtPositionY.setColumns(10);
	txtDelay.setColumns(10);
	btnShowToast.setUI(new BEButtonUI().setNormalColor(BEButtonUI.NormalColor.red));
	btnShowToast.setForeground(Color.white);
	
	// init btn pane
	JPanel btnPane = new JPanel(new FlowLayout(FlowLayout.CENTER));
	btnPane.add(new JLabel("Position x:"));
	btnPane.add(txtPositionX);
	btnPane.add(new JLabel("Position y:"));
	btnPane.add(txtPositionY);
	btnPane.add(new JLabel("Delay(ms):"));
	btnPane.add(txtDelay);
	btnPane.add(btnShowToast);
	
	// init main ui
	this.add(btnPane, BorderLayout.SOUTH);
	this.add(new JScrollPane(txtMsg), BorderLayout.CENTER);
	this.setBorder(BorderFactory.createEmptyBorder(10,100,20,100));
}
 
Example 8
Source File: OptionPaneDemo.java    From beautyeye with Apache License 2.0 4 votes vote down vote up
/**
    * OptionPaneDemo Constructor.
    *
    * @param swingset the swingset
    */
   public OptionPaneDemo(SwingSet2 swingset) {
// Set the title for this demo, and an icon used to represent this
// demo inside the SwingSet2 app.
super(swingset, "OptionPaneDemo"
		, "toolbar/JOptionPane.gif");

JPanel demo = getDemoPanel();

demo.setLayout(new BoxLayout(demo, BoxLayout.X_AXIS));

JPanel bp = new JPanel() {
    public Dimension getMaximumSize() {
	return new Dimension(getPreferredSize().width, super.getMaximumSize().height);
    }
};
bp.setLayout(new BoxLayout(bp, BoxLayout.Y_AXIS));

bp.add(Box.createRigidArea(VGAP30));
bp.add(Box.createRigidArea(VGAP30));

JButton b = createInputDialogButton();
b.setForeground(Color.white);
b.setUI(new BEButtonUI().setNormalColor(BEButtonUI.NormalColor.green));
bp.add(b);      bp.add(Box.createRigidArea(VGAP15));
bp.add(createWarningDialogButton());    bp.add(Box.createRigidArea(VGAP15));

JButton b3 = createComponentDialogButton();
b3.setForeground(Color.white);
b3.setUI(new BEButtonUI().setNormalColor(BEButtonUI.NormalColor.lightBlue));
bp.add(b3);    bp.add(Box.createRigidArea(VGAP15));

JButton b4 = createComponentDialogButton();
b4.setForeground(Color.white);
b4.setUI(new BEButtonUI().setNormalColor(BEButtonUI.NormalColor.blue));
bp.add(b4);    bp.add(Box.createRigidArea(VGAP15));

bp.add(createConfirmDialogButton());  bp.add(Box.createRigidArea(VGAP15));
JButton b2 = createComponentDialogButton();
b2.setForeground(Color.white);
b2.setUI(new BEButtonUI().setNormalColor(BEButtonUI.NormalColor.red));
bp.add(b2);    bp.add(Box.createVerticalGlue());

demo.add(Box.createHorizontalGlue());
demo.add(bp);
demo.add(Box.createHorizontalGlue());
   }
 
Example 9
Source File: FileChooserDemo.java    From beautyeye with Apache License 2.0 4 votes vote down vote up
/**
     * Creates the file chooser demo.
     */
    public void createFileChooserDemo() {
	theImage = new JLabel("");
	jpgIcon = createImageIcon("filechooser/jpgIcon.jpg", "jpg image");
	gifIcon = createImageIcon("filechooser/gifIcon.gif", "gif image");

	JPanel demoPanel = getDemoPanel();
	demoPanel.setLayout(new BoxLayout(demoPanel, BoxLayout.Y_AXIS));

	JPanel innerPanel = new JPanel();
	innerPanel.setLayout(new BoxLayout(innerPanel, BoxLayout.X_AXIS));

	demoPanel.add(Box.createRigidArea(VGAP10));
	demoPanel.add(innerPanel);
	demoPanel.add(Box.createRigidArea(VGAP10));

	innerPanel.add(Box.createRigidArea(HGAP20));

	// Create a panel to hold buttons
	JPanel buttonPanel = new JPanel() {
	    public Dimension getMaximumSize() {
		return new Dimension(getPreferredSize().width, super.getMaximumSize().height);
	    }
	};
	buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.Y_AXIS));

	buttonPanel.add(Box.createRigidArea(VGAP15));
	buttonPanel.add(createPlainFileChooserButton());
	buttonPanel.add(Box.createRigidArea(VGAP15));
	JButton btn = createPreviewFileChooserButton();
	btn.setUI(new BEButtonUI().setNormalColor(BEButtonUI.NormalColor.lightBlue));
	btn.setForeground(Color.white);
	buttonPanel.add(btn);
	buttonPanel.add(Box.createRigidArea(VGAP15));
	JButton btn2 = createCustomFileChooserButton();
	btn2.setUI(new BEButtonUI().setNormalColor(BEButtonUI.NormalColor.red));
	btn2.setForeground(Color.white);
	buttonPanel.add(btn2);
	buttonPanel.add(Box.createVerticalGlue());

	// Create a panel to hold the image
	JPanel imagePanel = new JPanel();//* comment by jb2011
//	JPanel imagePanel = N9ComponentFactory.createPanel_style1(new Insets(18,10,10,21));//* add by jb2011
	imagePanel.setLayout(new BorderLayout());
//	imagePanel.setBorder(new BevelBorder(BevelBorder.LOWERED));//* comment by jb2011
	JScrollPane scroller = new JScrollPane(theImage);
        scroller.getVerticalScrollBar().setUnitIncrement(10);
        scroller.getHorizontalScrollBar().setUnitIncrement(10);
//        scroller.setBorder(null);
//        scroller.setBackground(Color.red);
	imagePanel.add(scroller, BorderLayout.CENTER);

	// add buttons and image panels to inner panel
	innerPanel.add(buttonPanel);
	innerPanel.add(Box.createRigidArea(HGAP30));
	innerPanel.add(imagePanel);
	innerPanel.add(Box.createRigidArea(HGAP20));
    }