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

The following examples show how to use javax.swing.JButton#setForeground() . 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: NotificationImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private JComponent createDetails( String text, ActionListener action ) {
    if( null == action ) {
        return new JLabel(text);
    }
    try {
        text = "<html><u>" + XMLUtil.toElementContent(text); //NOI18N
    } catch( CharConversionException ex ) {
        throw new IllegalArgumentException(ex);
    }
    JButton btn = new JButton(text);
    btn.setFocusable(false);
    btn.setBorder(BorderFactory.createEmptyBorder());
    btn.setBorderPainted(false);
    btn.setFocusPainted(false);
    btn.setOpaque(false);
    btn.setContentAreaFilled(false);
    btn.addActionListener(action);
    btn.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    Color c = UIManager.getColor("nb.html.link.foreground"); //NOI18N
    if (c != null) {
        btn.setForeground(c);
    }
    return btn;
}
 
Example 2
Source File: ExpressionPane.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
public JButton createInsertButton(final String pattern) {
    JButton button = new JButton(pattern);
    button.setFont(insertCompFont);
    button.setForeground(insertCompColor);
    button.addActionListener(e -> insertCodePattern(pattern));
    return button;
}
 
Example 3
Source File: JSFConfigurationPanelVisual.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    JButton button = (JButton)value;
    if (isSelected) {
        button.setForeground(table.getSelectionForeground());
        button.setBackground(table.getSelectionBackground());
    } else {
        button.setForeground(table.getForeground());
        button.setBackground(UIManager.getColor("Button.background"));
    }
    return button;
}
 
Example 4
Source File: InstanceDataObjectTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@RandomlyFails // NB-Core-Build #2131, #2136 (both in IDOT and IDOT.LkpIDO)
public void testDeleteSettings() throws Exception {
    FileObject root = lfs.getRoot();
    DataFolder folder = DataFolder.findFolder(root);
    
    String filename = "testDeleteSettings";
    JButton obj = new JButton();
    InstanceDataObject ido = InstanceDataObject.create(folder, filename, obj, null, false);
    assertNotNull("InstanceDataObject.create cannot return null!", ido);
    
    // test if file object does not remain locked when ido is deleted and
    // the storing is not rescheduled in consequence of the serialization 
    obj.setForeground(Color.black);
    Thread.sleep(500);
    ido.delete();
    assertNull(filename + ".settings was not deleted!", root.getFileObject(filename));
    Thread.sleep(3000);
    assertNull(filename + ".settings was not deleted!", root.getFileObject(filename));
    
    filename = "testDeleteSettings2";
    Ser ser = new Ser("bla");
    ido = InstanceDataObject.create(folder, filename, ser, null, false);
    assertNotNull("InstanceDataObject.create cannot return null!", ido);
    
    ser.setProperty(10);
    ido.delete();
    assertNull(filename + ".settings was not deleted!", root.getFileObject(filename));
    Thread.sleep(3000);
    assertNull(filename + ".settings was not deleted!", root.getFileObject(filename));
}
 
Example 5
Source File: CompactLabourReport.java    From freecol with GNU General Public License v2.0 5 votes vote down vote up
private void addUnitTypes() {
    int row = 1;

    JButton allColonistsButton = createUnitNameButton(Messages.message("report.labour.allColonists"), labourData.getSummary());
    reportPanel.add(allColonistsButton, "cell " + COLONY_COLUMN + " " + row + " 1 " + labourData.getSummary().getUnitSummaryRowCount());

    row = addLocationData(labourData.getSummary().getTotal(), null, row);

    for (UnitType unitType : LabourData.getLabourTypes(getMyPlayer())) {
        LabourData.UnitData unitData = labourData.getUnitData(unitType);

        JButton unitButton = createUnitNameButton(unitData.getUnitName(), unitData);
        int rows = unitData.getUnitSummaryRowCount();
        reportPanel.add(unitButton, "cell " + COLONY_COLUMN + " " + row + " 1 " + rows);

        if (unitData.hasDetails()) {
            row = addLocationData(unitData.getTotal(), null, row);
        } else {
            unitButton.setEnabled(false);
            unitButton.setDisabledIcon(unitButton.getIcon());
            unitButton.setForeground(Color.GRAY);

            reportPanel.add(createEmptyLabel(), "cell " + UNIT_TYPE_COLUMN + " " + row + " " + (COLUMNS - 1) + " 1");
            row++;
        }
    }
}
 
Example 6
Source File: CompactLabourReport.java    From freecol with GNU General Public License v2.0 5 votes vote down vote up
private JButton createButton(String name, ActionListener listener) {
    JButton button = new JButton(name);
    button.setMargin(new Insets(0, 0, 0, 0));
    button.setOpaque(false);
    button.setHorizontalAlignment(SwingConstants.LEADING);
    button.setForeground(Utility.LINK_COLOR);
    button.setBorder(Utility.LEFTCELLBORDER);
    button.addActionListener(listener);
    return button;
}
 
Example 7
Source File: SignIn.java    From dctb-utfpr-2018-1 with Apache License 2.0 5 votes vote down vote up
public JButton styleButtons(){
    JButton submit = new JButton();
    Color colorForeground = new Color(0x8D8D8D);
    Color colorBackground = new Color(0xF1F1F1);
    submit.setForeground(colorForeground);
    submit.setBackground(colorBackground);
    Border line = new LineBorder(colorForeground);
    Border margin = new EmptyBorder(5, 15, 5, 15);
    Border compound = new CompoundBorder(line, margin);
    submit.setBorder(compound);
    submit.setAlignmentX(Component.CENTER_ALIGNMENT);
    return submit;
}
 
Example 8
Source File: ContactsPanel.java    From xyTalk-pc with GNU Affero General Public License v3.0 5 votes vote down vote up
private void initComponents() {
	keboardPanel = new JPanel();
	keboardPanel.setBackground(Colors.DARK);
	for (int i=0; i < keys.length; i++) {
		JButton btn = new JButton();
		btn.setBackground(Colors.DARK);
		btn.setForeground(Colors.FONT_WHITE);
		btn.setText(String.valueOf(keys[i]));
		btn.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				
				refreshData(btn.getText());
				super.mouseClicked(e);
				
			}
		});
		keboardPanel.add(btn);
	}
	
       ImageIcon sendingIcon = new ImageIcon(getClass().getResource("/image/loading7.gif"));
       loadingProgress.setIcon(sendingIcon);
       loadingProgress.setVisible(false);
       
       keboardPanel.add(loadingProgress, new GBC(0, 0).setFill(GBC.BOTH).setWeight(1, 1).setInsets(0, 0, 0, 0));	
       
	contactsListView = new RCListView();
}
 
Example 9
Source File: FatalErrorDialog.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public FatalErrorDialog addButton(String message, Runnable action)
{
	JButton button = new JButton(message);
	button.addActionListener(e -> action.run());
	button.setFont(font);
	button.setBackground(ColorScheme.DARK_GRAY_COLOR);
	button.setForeground(Color.LIGHT_GRAY);
	button.setBorder(BorderFactory.createCompoundBorder(
		BorderFactory.createMatteBorder(1, 0, 0, 0, ColorScheme.DARK_GRAY_COLOR.brighter()),
		new EmptyBorder(4, 4, 4, 4)
	));
	button.setAlignmentX(Component.CENTER_ALIGNMENT);
	button.setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
	button.setFocusPainted(false);
	button.addChangeListener(ev ->
	{
		if (button.getModel().isPressed())
		{
			button.setBackground(ColorScheme.DARKER_GRAY_COLOR);
		}
		else if (button.getModel().isRollover())
		{
			button.setBackground(ColorScheme.DARK_GRAY_HOVER_COLOR);
		}
		else
		{
			button.setBackground(ColorScheme.DARK_GRAY_COLOR);
		}
	});

	rightColumn.add(button);
	rightColumn.revalidate();

	return this;
}
 
Example 10
Source File: SampleAnalysisWorkflowManagerLAICPMS.java    From ET_Redux with Apache License 2.0 5 votes vote down vote up
private void addFractionRow(AliquotInterface aliquot, ETFractionInterface tempFrac, int row, int max) {

        // nov 2009 Note button for fractions
        JButton tempJB = new EditFractionButton("Note", row, true);
        tuneNotesButton(tempJB, tempFrac.getFractionNotes());
        tempJB.setForeground(Color.red);
        //tempJB.setToolTipText("Click to Annotate Fraction.");
        tempJB.setMargin(new Insets(0, 0, 0, 0));
        tempJB.addActionListener(new ShowFractionNotesListener(tempFrac));
        fractionNoteButtons.add(tempJB);
        modifyComponentKeyMapForTable(tempJB, fractionNoteButtons, max);

        // fraction name
        insertTableTextField(fractionID, max);
    }
 
Example 11
Source File: BatchDownloadWnd.java    From xdm with GNU General Public License v2.0 5 votes vote down vote up
private JButton createButton(String name) {
	JButton btn = new CustomButton(StringResource.get(name));
	btn.setBackground(ColorResource.getDarkBtnColor());
	btn.setBorderPainted(false);
	btn.setFocusPainted(false);
	btn.setForeground(Color.WHITE);
	btn.setFont(FontResource.getNormalFont());
	btn.addActionListener(this);
	return btn;
}
 
Example 12
Source File: NegotiationDialog.java    From freecol with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets a trade item button for a given item.
 *
 * @param item The {@code TradeItem} to make a button for.
 * @param saleDir Boolean to indicate the EU price for sale (T) or buy (F)
 * @return A new {@code JButton} for the item.
 */
private JButton getTradeItemButton(TradeItem item, boolean saleDir) {
    
    Market market = getMyPlayer().getMarket();
    JButton button = new JButton(new RemoveAction(item));
    
    // Checks if the items are goods
    if (item.getGoods() != null) {
        int buyPriceTotal = market.getBidPrice(item.getGoods().getType(), item.getGoods().getAmount());
        int salePriceTotal = market.getSalePrice(item.getGoods().getType(), item.getGoods().getAmount());
        
        // Depending on saleDir, creates a button for goods w/ EU buy or sale price
        if (saleDir) {
            button.setText(Messages.message(item.getLabel()) + " " +
                    Messages.message(StringTemplate
                            .template("negotiationDialog.euSalePrice")
                            .addAmount("%priceTotal%", salePriceTotal)));
        } else {
            button.setText(Messages.message(item.getLabel()) + " " +
                    Messages.message(StringTemplate
                            .template("negotiationDialog.euBuyPrice")
                            .addAmount("%priceTotal%", buyPriceTotal)));
        }
    } else {
        // If not goods, follow protocol
        button.setText(Messages.message(item.getLabel()));
    }
    
    button.setMargin(Utility.EMPTY_MARGIN);
    button.setOpaque(false);
    button.setForeground(Utility.LINK_COLOR);
    button.setBorder(Utility.blankBorder(0, 0, 0, 0));
    button.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    return button;
}
 
Example 13
Source File: ComponentInstaller.java    From xdm with GNU General Public License v2.0 5 votes vote down vote up
private JButton createButton2() {
	JButton btn = new CustomButton("Cancel");
	btn.setBackground(ColorResource.getDarkBtnColor());
	btn.setBorderPainted(false);
	btn.setFocusPainted(false);
	btn.setForeground(Color.WHITE);
	btn.setFont(FontResource.getNormalFont());
	return btn;
}
 
Example 14
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 15
Source File: MediaDownloaderWnd.java    From xdm with GNU General Public License v2.0 5 votes vote down vote up
private JButton createButton(String name) {
	JButton btn = new CustomButton(StringResource.get(name));
	btn.setBackground(ColorResource.getDarkBtnColor());
	btn.setBorderPainted(false);
	btn.setFocusPainted(false);
	btn.setForeground(Color.WHITE);
	btn.setFont(FontResource.getNormalFont());
	btn.addActionListener(this);
	return btn;
}
 
Example 16
Source File: MessageBox.java    From xdm with GNU General Public License v2.0 5 votes vote down vote up
void applyStyle(JButton btn) {
	btn.addActionListener(this);
	btn.setBackground(ColorResource.getDarkerBgColor());// );
	btn.setForeground(Color.WHITE);
	btn.setFocusable(true);
	// btn.setForeground(Color.WHITE);
	btn.setFont(FontResource.getBigFont());
	btn.setBorderPainted(false);
	btn.setMargin(new Insets(0, 0, 0, 0));
	// btn.setFocusPainted(false);
	btn.getInputMap(WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "pressed");
	btn.getInputMap(WHEN_FOCUSED).put(KeyStroke.getKeyStroke("released ENTER"), "released");
}
 
Example 17
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 18
Source File: GraphFrame.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
private void setRedOutline(JButton but, boolean red) {
	if (red) {	
		//but.setBackground(Color.RED);
		but.setForeground(Color.BLACK);
		but.setBackground(Color.GRAY);
	} else
		but.setForeground(Color.GRAY);
		but.setBackground(Color.WHITE);
}
 
Example 19
Source File: ButtonHtmlDemo.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
public ButtonHtmlDemo() {
    ImageIcon leftButtonIcon = createImageIcon("images/right.gif");
    ImageIcon middleButtonIcon = createImageIcon("images/middle.gif");
    ImageIcon rightButtonIcon = createImageIcon("images/left.gif");

    b1 = new JButton("<html><center><b><u>D</u>isable</b><br>" + "<font color=#ffffdd>middle button</font>", leftButtonIcon);
    Font font = b1.getFont().deriveFont(Font.PLAIN);
    b1.setFont(font);
    b1.setVerticalTextPosition(AbstractButton.CENTER);
    b1.setHorizontalTextPosition(AbstractButton.LEADING); // aka LEFT, for
                                                          // left-to-right
                                                          // locales
    b1.setMnemonic(KeyEvent.VK_D);
    b1.setActionCommand("disable");

    b2 = new JButton("middle button", middleButtonIcon);
    b2.setFont(font);
    b2.setForeground(new Color(0xffffdd));
    b2.setVerticalTextPosition(AbstractButton.BOTTOM);
    b2.setHorizontalTextPosition(AbstractButton.CENTER);
    b2.setMnemonic(KeyEvent.VK_M);

    b3 = new JButton("<html><center><b><u>E</u>nable</b><br>" + "<font color=#ffffdd>middle button</font>", rightButtonIcon);
    b3.setFont(font);
    // Use the default text position of CENTER, TRAILING (RIGHT).
    b3.setMnemonic(KeyEvent.VK_E);
    b3.setActionCommand("enable");
    b3.setEnabled(false);

    // Listen for actions on buttons 1 and 3.
    b1.addActionListener(this);
    b3.addActionListener(this);

    b1.setToolTipText("Click this button to disable the middle button.");
    b2.setToolTipText("This middle button does nothing when you click it.");
    b3.setToolTipText("Click this button to enable the middle button.");

    // Add Components to this container, using the default FlowLayout.
    add(b1);
    add(b2);
    add(b3);
}
 
Example 20
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));
    }