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

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

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

JPanel.setBackground介绍

暂无

代码示例

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

private JPanel createInfoPanel(String text)
{
  JPanel panel = new JPanel(new BorderLayout());
  panel.setBorder(new EmptyBorder(7, 8, 6, 8));
  panel.setBackground(ColorScheme.DARK_GRAY_COLOR);
  JLabel infoLabel = new JShadowedLabel(text);
  infoLabel.setForeground(ColorScheme.LIGHT_GRAY_COLOR.darker());
  infoLabel.setFont(FontManager.getRunescapeSmallFont());
  panel.add(infoLabel);
  return panel;
}

代码示例来源:origin: stanfordnlp/CoreNLP

/**
 * Remove all trees from the display
 */
public void clearMatches() {
 JPanel spaceholder = new JPanel();
 spaceholder.setBackground(Color.white);
 scroller.setViewportView(spaceholder);
 scroller.validate();
 scroller.repaint();
 matchedPartCoordinates = null;
 matchedPartCoordinateIdx = -1;
}

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

public CategoryNodeRenderer() {
 _panel.setBackground(UIManager.getColor("Tree.textBackground"));
 if (_sat == null) {
  // Load the satellite image.
  String resource =
    "/org/apache/log4j/lf5/viewer/images/channelexplorer_satellite.gif";
  URL satURL = getClass().getResource(resource);
  _sat = new ImageIcon(satURL);
 }
 setOpaque(false);
 _checkBox.setOpaque(false);
 _panel.setOpaque(false);
 // The flowlayout set to LEFT is very important so that the editor
 // doesn't jump around.
 _panel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
 _panel.add(_checkBox);
 _panel.add(this);
 setOpenIcon(_sat);
 setClosedIcon(_sat);
 setLeafIcon(_sat);
}

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

AdvancedBevelBorder border = new AdvancedBevelBorder(new Color(120, 172, 220), new Color(55, 93, 128),
    new Color(73, 124, 169), new Color(150, 191, 229), new Color(36, 83, 126), 10);
JPanel panel = new JPanel() {
  @Override
  public Dimension getPreferredSize() {
    return new Dimension(200, 60);
  }
};
panel.setBackground(new Color(91, 154, 212));
panel.setBorder(border);

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

/**
 * This method solves the known issue with Nimbus LAF background
 * transparency and background color.
 *
 * @param color
 */
public void setExtBackgroundColor(Color color) {
  setBackground(new Color(0, 0, 0, 0));
  JPanel jPanel = new JPanel();
  jPanel.setBackground(color);
  setLayout(new BorderLayout());
  add(jPanel);
}

代码示例来源:origin: haraldk/TwelveMonkeys

JPanel panel = new JPanel();
panel.setBackground(Color.WHITE);
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

代码示例来源:origin: apache/ignite

/**
 * @return Panel with banner.
 */
private JPanel createBannerPanel() {
  JPanel bannerPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 5));
  bannerPanel.setBackground(Color.WHITE);
  try {
    URL url = new URL(bannerSpec);
    BufferedImage image = ImageIO.read(url);
    bannerPanel.add(new JLabel(new ImageIcon(image)));
  }
  catch (IOException ioe) {
    ioe.printStackTrace();
  }
  JPanel msgPanel = new JPanel();
  msgPanel.setLayout(new BoxLayout(msgPanel, BoxLayout.Y_AXIS));
  msgPanel.setBackground(Color.WHITE);
  msgPanel.add(new JLabel("<html><b>About Ignite</b></html>"));
  msgPanel.add(Box.createVerticalStrut(5));
  msgPanel.add(new JLabel(appName));
  bannerPanel.add(msgPanel);
  return bannerPanel;
}

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

private void fillUnavailabilityPenaltyCells(TennisSolution tennisSolution) {
  for (UnavailabilityPenalty unavailabilityPenalty : tennisSolution.getUnavailabilityPenaltyList()) {
    JPanel unavailabilityPanel = new JPanel();
    unavailabilityPanel.setBackground(TangoColorFactory.ALUMINIUM_4);
    datesPanel.addCell(unavailabilityPenalty.getDay(), unavailabilityPenalty.getTeam(),
        unavailabilityPanel);
  }
}

代码示例来源:origin: MovingBlocks/Terasology

MyRenderer() {
  setBackground(BACKGROUND);
  setLayout(new BorderLayout());
  pHead.setLayout(new BorderLayout());
  pHead.setBackground(BACKGROUND);
  pHead.add(pList, BorderLayout.LINE_START);
  pHead.add(lActive, BorderLayout.LINE_END);
  pHead.add(pError, BorderLayout.PAGE_END);
  lId.setHorizontalAlignment(SwingConstants.RIGHT);
  lName.setForeground(Color.BLUE);
  lCounters.setForeground(Color.GRAY);
  pList.setLayout(new FlowLayout(FlowLayout.LEFT, 4, 2));
  pList.setBackground(BACKGROUND);
  pList.add(lId);
  pList.add(lName);
  pList.add(lCounters);
  pError.setVisible(false);
  pError.setLayout(new FlowLayout(FlowLayout.LEFT, 4, 2));
  pError.setBackground(BACKGROUND);
  pError.add(lErrorSpacer);
  pError.add(lError);
  lError.setForeground(Color.RED);
  add(pHead, BorderLayout.PAGE_START);
}

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

((JSpinner.DefaultEditor)((JSpinner)component).getEditor()).getTextField().setColumns(4);
JPanel descriptionPanel = new JPanel();
descriptionPanel.setLayout(new GridBagLayout());
getContentPane().add(
  descriptionPanel,
  new GridBagConstraints(0, 0, 2, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0,
    0), 0, 0));
descriptionPanel.setBackground(Color.white);
descriptionPanel.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.black));
  descriptionPanel.add(descriptionText, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER,
    GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0));
  descriptionText.setWrapStyleWord(true);
JPanel panel = new JPanel();
getContentPane().add(
  panel,
  new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 5, 0,
    5), 0, 0));
panel.add(new JLabel(name + ":"));
panel.add(component);
JPanel buttonPanel = new JPanel();
getContentPane().add(
  buttonPanel,
setSize(new Dimension(320, 175));

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

((JSpinner.DefaultEditor)((JSpinner)component).getEditor()).getTextField().setColumns(4);
JPanel descriptionPanel = new JPanel();
descriptionPanel.setLayout(new GridBagLayout());
getContentPane().add(
  descriptionPanel,
  new GridBagConstraints(0, 0, 2, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0,
    0), 0, 0));
descriptionPanel.setBackground(Color.white);
descriptionPanel.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.black));
  descriptionPanel.add(descriptionText, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER,
    GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0));
  descriptionText.setWrapStyleWord(true);
JPanel panel = new JPanel();
getContentPane().add(
  panel,
  new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 5, 0,
    5), 0, 0));
panel.add(new JLabel(name + ":"));
panel.add(component);
JPanel buttonPanel = new JPanel();
getContentPane().add(
  buttonPanel,
setSize(new Dimension(320, 175));

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

private JPanel buildCheckboxPanel(SkillDataBonus bonus)
{
  JPanel uiOption = new JPanel(new BorderLayout());
  JLabel uiLabel = new JLabel(bonus.getName());
  JCheckBox uiCheckbox = new JCheckBox();
  uiLabel.setForeground(Color.WHITE);
  uiLabel.setFont(FontManager.getRunescapeSmallFont());
  uiOption.setBorder(BorderFactory.createEmptyBorder(3, 7, 3, 0));
  uiOption.setBackground(ColorScheme.DARKER_GRAY_COLOR);
  // Adjust XP bonus depending on check-state of the boxes.
  uiCheckbox.addActionListener(event -> adjustCheckboxes(uiCheckbox, bonus));
  uiCheckbox.setBackground(ColorScheme.MEDIUM_GRAY_COLOR);
  uiOption.add(uiLabel, BorderLayout.WEST);
  uiOption.add(uiCheckbox, BorderLayout.EAST);
  bonusCheckBoxes.add(uiCheckbox);
  return uiOption;
}

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

JPanel a = new JPanel();
 JPanel b = new JPanel();
 JPanel c = new JPanel();
 a.setBackground( Color.RED );
 b.setBackground( Color.GREEN  );
 c.setBackground( Color.BLUE );
 a.setMaximumSize( new Dimension(  10, 10) );
 b.setMaximumSize( new Dimension(  50, 10) );
 a.setAlignmentX( Component.LEFT_ALIGNMENT );//0.0
 b.setAlignmentX( Component.LEFT_ALIGNMENT );//0.0
 c.setAlignmentX( Component.LEFT_ALIGNMENT );//0.0
 JPanel panel = new JPanel();
 panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
 panel.add(a);
 panel.add(b);
 panel.add(c); 
 int result = JOptionPane.showConfirmDialog(null, panel, "Please enter values.", JOptionPane.OK_CANCEL_OPTION);

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

private JComponent getCenterPanel() {
  JPanel center = new JPanel(new BorderLayout());
  center.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
  center.setBackground(Color.WHITE);
  JTextArea license = new javax.swing.JTextArea();
  license.setLineWrap(true);
  license.setWrapStyleWord(true);
  license.setEditable(false);
  license.setFont(license.getFont().deriveFont(11.0f));
  StringBuilder licenseText = new StringBuilder();
  licenseText.append("Enhance current Java (JRE/JDK) installations with DCEVM (http://github.com/dcevm/dcevm).");
  licenseText.append("\n\nYou can either replace current Java VM or install DCEVM as alternative JVM (run with -XXaltjvm=dcevm command-line option).");
  licenseText.append("\nInstallation as alternative JVM is preferred, it gives you more control where you will use DCEVM.\nWhy this is important? Because DCEVM forces your JVM to use only one GC algorithm, and this may cause performance penalty.");
  licenseText.append("\n\n\nThis program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 only, as published by the Free Software Foundation.\n\nThis code is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License version 2 for more details (a copy is included in the LICENSE file that accompanied this code).\n\nYou should have received a copy of the GNU General Public License version 2 along with this work; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.");
  licenseText.append("\n\n\nASM LICENSE TEXT:\nCopyright (c) 2000-2005 INRIA, France Telecom\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\n\n1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\n\n2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.\n\n3. Neither the name of the copyright holders nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.");
  license.setText(licenseText.toString());
  JScrollPane licenses = new JScrollPane(license, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
  licenses.setPreferredSize(new Dimension(150, 150));
  center.add(licenses, BorderLayout.NORTH);
  center.add(getChooserPanel(), BorderLayout.CENTER);
  return center;
}

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

private JPanel createHeaderPanel(String title, String type, boolean largePadding, ActionListener actionListener)
{
  JPanel panel = new JPanel(new BorderLayout());
  panel.setBorder(new EmptyBorder(largePadding ? 11 : 0, 0, 0, 0));
  panel.setBackground(ColorScheme.DARK_GRAY_COLOR);
  JLabel headerLabel = new JLabel(title);
  headerLabel.setForeground(Color.WHITE);
  headerLabel.setFont(FontManager.getRunescapeSmallFont());
  panel.add(headerLabel, BorderLayout.CENTER);
  IconButton addButton = new IconButton(ADD_ICON, ADD_ICON_HOVER);
  addButton.setPreferredSize(new Dimension(14, 14));
  addButton.setToolTipText("Add a " + type);
  addButton.addActionListener(actionListener);
  panel.add(addButton, BorderLayout.EAST);
  return panel;
}

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

JPanel container = new JPanel();
container.setBackground(ColorScheme.DARKER_GRAY_COLOR);
container.setLayout(new BorderLayout());
container.setBorder(new EmptyBorder(10, 10, 10, 10));
final Color pressedColor = ColorScheme.DARKER_GRAY_COLOR.brighter();
JLabel iconLabel = new JLabel(icon);
container.add(iconLabel, BorderLayout.WEST);
JPanel textContainer = new JPanel();
textContainer.setBackground(ColorScheme.DARKER_GRAY_COLOR);
textContainer.setLayout(new GridLayout(2, 1));
textContainer.setBorder(new EmptyBorder(5, 10, 5, 10));
JLabel topLine = new JLabel(topText);
topLine.setForeground(Color.WHITE);
topLine.setFont(FontManager.getRunescapeSmallFont());
JLabel bottomLine = new JLabel(bottomText);
bottomLine.setForeground(Color.WHITE);
bottomLine.setFont(FontManager.getRunescapeSmallFont());
textContainer.add(topLine);
textContainer.add(bottomLine);
container.add(textContainer, BorderLayout.CENTER);

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

GrandExchangeOffersPanel()
{
  setLayout(new BorderLayout());
  setBackground(ColorScheme.DARK_GRAY_COLOR);
  constraints.fill = GridBagConstraints.HORIZONTAL;
  constraints.weightx = 1;
  constraints.gridx = 0;
  constraints.gridy = 0;
  /* This panel wraps the offers panel and limits its height */
  JPanel offersWrapper = new JPanel(new BorderLayout());
  offersWrapper.setBackground(ColorScheme.DARK_GRAY_COLOR);
  offersWrapper.add(offerPanel, BorderLayout.NORTH);
  offerPanel.setLayout(new GridBagLayout());
  offerPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
  offerPanel.setBackground(ColorScheme.DARK_GRAY_COLOR);
  /* This panel wraps the error panel and limits its height */
  JPanel errorWrapper = new JPanel(new BorderLayout());
  errorWrapper.setBackground(ColorScheme.DARK_GRAY_COLOR);
  /*  The error panel, this displays an error message */
  PluginErrorPanel errorPanel = new PluginErrorPanel();
  errorWrapper.add(errorPanel, BorderLayout.NORTH);
  errorPanel.setBorder(new EmptyBorder(50, 20, 20, 20));
  errorPanel.setContent("No offers detected", "No grand exchange offers were found on your account.");
  container.add(offersWrapper, OFFERS_PANEL);
  container.add(errorWrapper, ERROR_PANEL);
  add(container, BorderLayout.CENTER);
  resetOffers();
}

代码示例来源:origin: 4thline/cling

public Component getTableCellEditorComponent(JTable jTable, Object o, boolean b, int i, int i1) {
  if (getArgument().getDirection().equals(ActionArgument.Direction.OUT)) {
    if (textField.getText() != null && textField.getText().length() > 50) {
      JPanel panel = new JPanel();
      panel.setBackground(Color.WHITE);
      panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
      JButton expandButton = new JButton("Expand");
      expandButton.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent actionEvent) {
              onExpandText(textField.getText());
            }
          }
      );
      panel.add(textField);
      panel.add(expandButton);
      return panel;
    }
    return textField;
  }
  return textField;
}

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

fontPanel.add(fontSizeSpinner, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.WEST,
    GridBagConstraints.NONE, new Insets(0, 0, 5, 10), 0, 0));
  ((JSpinner.DefaultEditor)fontSizeSpinner.getEditor()).getTextField().setColumns(2);
  fontPanel.add(fontScroll, new GridBagConstraints(1, 1, 3, 1, 1.0, 1.0, GridBagConstraints.CENTER,
    GridBagConstraints.BOTH, new Insets(0, 0, 5, 5), 0, 0));
  fontPanel.add(new JLabel("Size:"), new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.EAST,
    GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));
  unicodePanel = new JPanel(new GridBagLayout());
    GridBagConstraints.NONE, new Insets(0, 0, 0, 5), 0, 0));
    bitmapPanel.add(new JLabel("Gamma:"), new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST,
      GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));
  fontPanel.add(new JLabel("Rendering:"), new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST,
    GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));
samplePanel.setLayout(new GridBagLayout());
samplePanel.setBorder(BorderFactory.createTitledBorder("Sample Text"));
  wrapperPanel.setLayout(new BorderLayout());
  wrapperPanel.setBackground(java.awt.Color.white);
    gamePanel.setLayout(new BorderLayout());
    gamePanel.setBackground(java.awt.Color.white);

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

fontPanel.add(fontSizeSpinner, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.WEST,
    GridBagConstraints.NONE, new Insets(0, 0, 5, 10), 0, 0));
  ((JSpinner.DefaultEditor)fontSizeSpinner.getEditor()).getTextField().setColumns(2);
  fontPanel.add(fontScroll, new GridBagConstraints(1, 1, 3, 1, 1.0, 1.0, GridBagConstraints.CENTER,
    GridBagConstraints.BOTH, new Insets(0, 0, 5, 5), 0, 0));
  fontPanel.add(new JLabel("Size:"), new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.EAST,
    GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));
  unicodePanel = new JPanel(new GridBagLayout());
    GridBagConstraints.NONE, new Insets(0, 0, 0, 5), 0, 0));
    bitmapPanel.add(new JLabel("Gamma:"), new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST,
      GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));
  fontPanel.add(new JLabel("Rendering:"), new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST,
    GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));
samplePanel.setLayout(new GridBagLayout());
samplePanel.setBorder(BorderFactory.createTitledBorder("Sample Text"));
  wrapperPanel.setLayout(new BorderLayout());
  wrapperPanel.setBackground(java.awt.Color.white);
    gamePanel.setLayout(new BorderLayout());
    gamePanel.setBackground(java.awt.Color.white);

相关文章

微信公众号

最新文章

更多

JPanel类方法