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

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

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

JButton.setBackground介绍

暂无

代码示例

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

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

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

JButton button = new JButton();
button.setBackground(Color.red);
button.setOpaque(true);
button.setBorderPainted(false);

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

private JButton createButton(Lecture lecture, Color color, String toolTip) {
  JButton button = SwingUtils.makeSmallButton(new JButton(new LectureAction(lecture)));
  button.setBackground(color);
  if (lecture.isPinned()) {
    button.setIcon(CommonIcons.PINNED_ICON);
  }
  button.setToolTipText(toolTip);
  return button;
}

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

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

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

private JButton createButton(Exam exam, Color color, String toolTip) {
  JButton button = SwingUtils.makeSmallButton(new JButton(new ExamAction(exam)));
  button.setBackground(color);
  button.setToolTipText(toolTip);
  if (exam instanceof FollowingExam) {
    button.setForeground(TangoColorFactory.ALUMINIUM_5);
  }
  return button;
}

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

private JButton createButton(TeamAssignment teamAssignment, Color color) {
  JButton button = SwingUtils.makeSmallButton(new JButton(new TeamAssignmentAction(teamAssignment)));
  button.setBackground(color);
  if (teamAssignment.isPinned()) {
    button.setIcon(CommonIcons.PINNED_ICON);
  }
  return button;
}

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

private JButton createButton(Match match, Team team, Team otherTeam, String toolTip) {
  Color color = determinePlanningEntityColor(match, otherTeam);
  String label = otherTeam.getLabel();
  JButton button = SwingUtils.makeSmallButton(new JButton(new MatchAction(match, label)));
  if (match.getAwayTeam() == team) {
    button.setIcon(awayMatchIcon);
  }
  button.setBackground(color);
  button.setToolTipText(toolTip);
  return button;
}

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

public void addShiftAssignment(ShiftAssignment shiftAssignment) {
  Shift shift = shiftAssignment.getShift();
  JPanel shiftPanel = shiftPanelMap.get(shift);
  JButton shiftAssignmentButton = SwingUtils.makeSmallButton(new JButton(new ShiftAssignmentAction(shiftAssignment)));
  shiftAssignmentButton.setEnabled(shiftPanel.isEnabled());
  if (employee != null) {
    if (employee.getDayOffRequestMap().containsKey(shift.getShiftDate())
        || employee.getShiftOffRequestMap().containsKey(shift)) {
      shiftAssignmentButton.setForeground(TangoColorFactory.SCARLET_1);
    }
  }
  Color color = nurseRosteringPanel.determinePlanningEntityColor(shiftAssignment, shift.getShiftType());
  shiftAssignmentButton.setBackground(color);
  String toolTip = nurseRosteringPanel.determinePlanningEntityTooltip(shiftAssignment);
  shiftAssignmentButton.setToolTipText(toolTip);
  shiftPanel.add(shiftAssignmentButton);
  shiftPanel.repaint();
  shiftAssignmentButtonMap.put(shiftAssignment, shiftAssignmentButton);
}

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

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

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

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

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

private static JButton createSimpleButton(String text) {
 JButton button = new JButton(text);
 button.setForeground(Color.BLACK);
 button.setBackground(Color.WHITE);
 Border line = new LineBorder(Color.BLACK);
 Border margin = new EmptyBorder(5, 15, 5, 15);
 Border compound = new CompoundBorder(line, margin);
 button.setBorder(compound);
 return button;
}

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

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

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

lastLine.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
this.buttonClose = new JButton("Close");
this.buttonClose.setBorder(BorderFactory.createCompoundBorder(
  HelperUi.BORDER_FOCUS_GAINED,
Container dialogPane = this.getContentPane();
final JButton buttonWebpage = new JButton("Webpage");
buttonWebpage.setBorder(BorderFactory.createCompoundBorder(
  HelperUi.BORDER_FOCUS_GAINED,
buttonWebpage.setBackground(new Color(200, 221, 242));
this.buttonClose.setBackground(new Color(200, 221, 242));

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

public static JXPanel getDescription(CardView card, int width, int height) {
  JXPanel descriptionPanel = new JXPanel();
  //descriptionPanel.setAlpha(.8f);
  descriptionPanel.setBounds(0, 0, width, height);
  descriptionPanel.setVisible(false);
  descriptionPanel.setLayout(null);
  //descriptionPanel.setBorder(BorderFactory.createLineBorder(Color.green));
  JButton j = new JButton("");
  j.setBounds(0, 0, width, height);
  j.setBackground(Color.black);
  j.setLayout(null);
  JLabel cardText = new JLabel();
  cardText.setBounds(5, 5, width - 10, height - 10);
  cardText.setForeground(Color.white);
  cardText.setFont(cardNameFont);
  cardText.setVerticalAlignment(SwingConstants.TOP);
  j.add(cardText);
  TextLines textLines = GuiDisplayUtil.getTextLinesfromCardView(card);
  cardText.setText(getRulefromCardView(card, textLines).toString());
  descriptionPanel.add(j);
  return descriptionPanel;
}

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

buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
JButton buttonCollect = new JButton("collect");
buttonCollect.setPreferredSize(new Dimension(100, 30));
buttonCollect.setEnabled(false);
buttonBase = new JButton("base");
buttonBase.setPreferredSize(new Dimension(100, 30));
buttonBase.setEnabled(true);
buttonTrain = new JButton("train");
buttonTrain.setPreferredSize(new Dimension(100, 30));
buttonTrain.setEnabled(false);
buttonTrain.setBackground(Color.cyan.darker());
buttonRecord.setPreferredSize(new Dimension(100, 30));
buttonRecord.setEnabled(true);
buttonRecord.setBackground(new Color(60, 255, 120));

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

JButton button1 = MakeGameButton(...);
JButton button2 = MakeGameButton(...);

JButton buttonA = new JButton("A Button");

buttonA.addActionListener(new ActionListener(){
  public void actionPerformed(ActionEvent e){
     button1.setBackground(...);
  }
});

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

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

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

private newButton(String label, Color background) {
  JButton button = new JButton(label);
  button.setBackground(background);
  return button;
}

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

JButton b = new JButton("foo");
b.addMouseListener(new MouseAdapter(){

  @Override
  public void mousePressed(MouseEvent e) {
    b.setBackground(Color.red);
  }

  @Override
  public void mouseReleased(MouseEvent e) {
    //go back to original state
  }

});

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

for (int i = 0; i < 20; i++) {
  final JButton btnBookFlight = new JButton("Book" + i);
  btnBookFlight.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent arg0) {
      btnBookFlight.setBackground(Color.RED);
      ...
    }
  });
}

相关文章

JButton类方法