javax.swing.JButton.setBackground()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(220)

本文整理了Java中javax.swing.JButton.setBackground()方法的一些代码示例,展示了JButton.setBackground()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JButton.setBackground()方法的具体详情如下:
包路径:javax.swing.JButton
类名称:JButton
方法名:setBackground

JButton.setBackground介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

  1. JButton button = new JButton("test");
  2. button.setBackground(Color.RED);
  3. button.setOpaque(true);

代码示例来源:origin: stackoverflow.com

  1. JButton button = new JButton();
  2. button.setBackground(Color.red);
  3. button.setOpaque(true);
  4. button.setBorderPainted(false);

代码示例来源:origin: kiegroup/optaplanner

  1. private JButton createButton(Lecture lecture, Color color, String toolTip) {
  2. JButton button = SwingUtils.makeSmallButton(new JButton(new LectureAction(lecture)));
  3. button.setBackground(color);
  4. if (lecture.isPinned()) {
  5. button.setIcon(CommonIcons.PINNED_ICON);
  6. }
  7. button.setToolTipText(toolTip);
  8. return button;
  9. }

代码示例来源:origin: kiegroup/optaplanner

  1. private JButton createButton(MeetingAssignment meetingAssignment, Color color) {
  2. JButton button = SwingUtils.makeSmallButton(new JButton(new MeetingAssignmentAction(meetingAssignment)));
  3. button.setBackground(color);
  4. return button;
  5. }

代码示例来源:origin: kiegroup/optaplanner

  1. private JButton createButton(Exam exam, Color color, String toolTip) {
  2. JButton button = SwingUtils.makeSmallButton(new JButton(new ExamAction(exam)));
  3. button.setBackground(color);
  4. button.setToolTipText(toolTip);
  5. if (exam instanceof FollowingExam) {
  6. button.setForeground(TangoColorFactory.ALUMINIUM_5);
  7. }
  8. return button;
  9. }

代码示例来源:origin: kiegroup/optaplanner

  1. private JButton createButton(TeamAssignment teamAssignment, Color color) {
  2. JButton button = SwingUtils.makeSmallButton(new JButton(new TeamAssignmentAction(teamAssignment)));
  3. button.setBackground(color);
  4. if (teamAssignment.isPinned()) {
  5. button.setIcon(CommonIcons.PINNED_ICON);
  6. }
  7. return button;
  8. }

代码示例来源:origin: kiegroup/optaplanner

  1. private JButton createButton(Match match, Team team, Team otherTeam, String toolTip) {
  2. Color color = determinePlanningEntityColor(match, otherTeam);
  3. String label = otherTeam.getLabel();
  4. JButton button = SwingUtils.makeSmallButton(new JButton(new MatchAction(match, label)));
  5. if (match.getAwayTeam() == team) {
  6. button.setIcon(awayMatchIcon);
  7. }
  8. button.setBackground(color);
  9. button.setToolTipText(toolTip);
  10. return button;
  11. }

代码示例来源:origin: kiegroup/optaplanner

  1. public void addShiftAssignment(ShiftAssignment shiftAssignment) {
  2. Shift shift = shiftAssignment.getShift();
  3. JPanel shiftPanel = shiftPanelMap.get(shift);
  4. JButton shiftAssignmentButton = SwingUtils.makeSmallButton(new JButton(new ShiftAssignmentAction(shiftAssignment)));
  5. shiftAssignmentButton.setEnabled(shiftPanel.isEnabled());
  6. if (employee != null) {
  7. if (employee.getDayOffRequestMap().containsKey(shift.getShiftDate())
  8. || employee.getShiftOffRequestMap().containsKey(shift)) {
  9. shiftAssignmentButton.setForeground(TangoColorFactory.SCARLET_1);
  10. }
  11. }
  12. Color color = nurseRosteringPanel.determinePlanningEntityColor(shiftAssignment, shift.getShiftType());
  13. shiftAssignmentButton.setBackground(color);
  14. String toolTip = nurseRosteringPanel.determinePlanningEntityTooltip(shiftAssignment);
  15. shiftAssignmentButton.setToolTipText(toolTip);
  16. shiftPanel.add(shiftAssignmentButton);
  17. shiftPanel.repaint();
  18. shiftAssignmentButtonMap.put(shiftAssignment, shiftAssignmentButton);
  19. }

代码示例来源:origin: kiegroup/optaplanner

  1. private JButton createTaskButton(Task task) {
  2. JButton taskButton = SwingUtils.makeSmallButton(new JButton(new TaskAction(task)));
  3. taskButton.setBackground(task.isPinned() ? TangoColorFactory.ALUMINIUM_3 : TangoColorFactory.ALUMINIUM_1);
  4. taskButton.setHorizontalTextPosition(SwingConstants.CENTER);
  5. taskButton.setVerticalTextPosition(SwingConstants.TOP);
  6. taskButton.setSize(task.getDuration(), ROW_HEIGHT);
  7. return taskButton;
  8. }

代码示例来源:origin: runelite/runelite

  1. colorPickerBtn = new JButton("Pick a color");
  2. colorPickerBtn = new JButton(ColorUtil.toHexColor(existingColor).toUpperCase());
  3. colorPickerBtn.setBackground(existingColor);
  4. colorPickerBtn.addMouseListener(new MouseAdapter()
  5. JButton resetButton = new JButton("Reset");
  6. resetButton.addActionListener((e) ->

代码示例来源:origin: stackoverflow.com

  1. private static JButton createSimpleButton(String text) {
  2. JButton button = new JButton(text);
  3. button.setForeground(Color.BLACK);
  4. button.setBackground(Color.WHITE);
  5. Border line = new LineBorder(Color.BLACK);
  6. Border margin = new EmptyBorder(5, 15, 5, 15);
  7. Border compound = new CompoundBorder(line, margin);
  8. button.setBorder(compound);
  9. return button;
  10. }

代码示例来源:origin: stackoverflow.com

  1. for(int i=1;i<=9;i++)
  2. {
  3. JButton btn = new JButton(String.valueOf(i));
  4. btn.setBackground(Color.BLACK);
  5. btn.setForeground(Color.GRAY);
  6. p3.add(btn);
  7. }

代码示例来源:origin: ron190/jsql-injection

  1. lastLine.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
  2. this.buttonClose = new JButton("Close");
  3. this.buttonClose.setBorder(BorderFactory.createCompoundBorder(
  4. HelperUi.BORDER_FOCUS_GAINED,
  5. Container dialogPane = this.getContentPane();
  6. final JButton buttonWebpage = new JButton("Webpage");
  7. buttonWebpage.setBorder(BorderFactory.createCompoundBorder(
  8. HelperUi.BORDER_FOCUS_GAINED,
  9. buttonWebpage.setBackground(new Color(200, 221, 242));
  10. this.buttonClose.setBackground(new Color(200, 221, 242));

代码示例来源:origin: magefree/mage

  1. public static JXPanel getDescription(CardView card, int width, int height) {
  2. JXPanel descriptionPanel = new JXPanel();
  3. //descriptionPanel.setAlpha(.8f);
  4. descriptionPanel.setBounds(0, 0, width, height);
  5. descriptionPanel.setVisible(false);
  6. descriptionPanel.setLayout(null);
  7. //descriptionPanel.setBorder(BorderFactory.createLineBorder(Color.green));
  8. JButton j = new JButton("");
  9. j.setBounds(0, 0, width, height);
  10. j.setBackground(Color.black);
  11. j.setLayout(null);
  12. JLabel cardText = new JLabel();
  13. cardText.setBounds(5, 5, width - 10, height - 10);
  14. cardText.setForeground(Color.white);
  15. cardText.setFont(cardNameFont);
  16. cardText.setVerticalAlignment(SwingConstants.TOP);
  17. j.add(cardText);
  18. TextLines textLines = GuiDisplayUtil.getTextLinesfromCardView(card);
  19. cardText.setText(getRulefromCardView(card, textLines).toString());
  20. descriptionPanel.add(j);
  21. return descriptionPanel;
  22. }

代码示例来源:origin: fossasia/neurolab-desktop

  1. buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
  2. JButton buttonCollect = new JButton("collect");
  3. buttonCollect.setPreferredSize(new Dimension(100, 30));
  4. buttonCollect.setEnabled(false);
  5. buttonBase = new JButton("base");
  6. buttonBase.setPreferredSize(new Dimension(100, 30));
  7. buttonBase.setEnabled(true);
  8. buttonTrain = new JButton("train");
  9. buttonTrain.setPreferredSize(new Dimension(100, 30));
  10. buttonTrain.setEnabled(false);
  11. buttonTrain.setBackground(Color.cyan.darker());
  12. buttonRecord.setPreferredSize(new Dimension(100, 30));
  13. buttonRecord.setEnabled(true);
  14. buttonRecord.setBackground(new Color(60, 255, 120));

代码示例来源:origin: stackoverflow.com

  1. JButton button1 = MakeGameButton(...);
  2. JButton button2 = MakeGameButton(...);
  3. JButton buttonA = new JButton("A Button");
  4. buttonA.addActionListener(new ActionListener(){
  5. public void actionPerformed(ActionEvent e){
  6. button1.setBackground(...);
  7. }
  8. });

代码示例来源:origin: stackoverflow.com

  1. public class Jbutton {
  2. public static void main (String[] args){
  3. //You're going to need some context for this like a JFrame
  4. JButton button = new JButton("I'm colorful!");
  5. button.setBackground(Color.RED);
  6. }
  7. }

代码示例来源:origin: stackoverflow.com

  1. private newButton(String label, Color background) {
  2. JButton button = new JButton(label);
  3. button.setBackground(background);
  4. return button;
  5. }

代码示例来源:origin: stackoverflow.com

  1. JButton b = new JButton("foo");
  2. b.addMouseListener(new MouseAdapter(){
  3. @Override
  4. public void mousePressed(MouseEvent e) {
  5. b.setBackground(Color.red);
  6. }
  7. @Override
  8. public void mouseReleased(MouseEvent e) {
  9. //go back to original state
  10. }
  11. });

代码示例来源:origin: stackoverflow.com

  1. for (int i = 0; i < 20; i++) {
  2. final JButton btnBookFlight = new JButton("Book" + i);
  3. btnBookFlight.addActionListener(new ActionListener() {
  4. public void actionPerformed(ActionEvent arg0) {
  5. btnBookFlight.setBackground(Color.RED);
  6. ...
  7. }
  8. });
  9. }

相关文章

JButton类方法