下面列出了javax.swing.JPanel#setBackground ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void initUI() {
toolbar = ProfilerToolbar.create(false);
JPanel p = new JPanel(new VerticalLayout(false, 6));
p.setOpaque(true);
p.setBackground(UIUtils.getProfilerResultsBackground());
HeapView defaultContent = createDefaultSummary();
if (defaultContent != null) content.add(0, defaultContent);
for (HeapView view : content) {
p.add(new ContentContainer(view));
ProfilerToolbar viewToolbar = view.getToolbar();
if (viewToolbar != null) toolbar.add(viewToolbar);
}
uiCreated(new ArrayList(content));
component = new ScrollableContainer(p);
content.clear();
content = null;
}
private JPanel getDock() {
JPanel dPanel = new JPanel(new GridLayout(7, 1));
dPanel.setOpaque(false);
dPanel.setBackground(new Color(0, 0, 0, 0));
testDesignButton = create("TestDesign");
testExecutionButton = create("TestExecution");
dashBoardButton = create("DashBoard");
dPanel.add(getLeftFiller());
dPanel.add(getLeftFiller());
dPanel.add(testDesignButton);
dPanel.add(testExecutionButton);
dPanel.add(dashBoardButton);
dPanel.add(getLeftFiller());
dPanel.add(getLeftFiller());
return dPanel;
}
public static JPanel createPanel(String title, int width, int height, int vGap, int hGap, int alignment, int type) {
FlowLayout flowLayout1 = new FlowLayout();
JPanel controlPanel = new JPanel();
controlPanel.setLayout(flowLayout1);
flowLayout1.setAlignment(alignment);
controlPanel.setPreferredSize(new java.awt.Dimension(width, height));
controlPanel.setBackground(JPlagCreator.SYSTEMCOLOR);
if (type == WITH_LINEBORDER)
controlPanel.setBorder(JPlagCreator.LINE);
if (type == WITH_TITLEBORDER)
controlPanel.setBorder(JPlagCreator.titleBorder(title, Color.BLACK, Color.BLACK));
flowLayout1.setVgap(vGap);
flowLayout1.setHgap(hGap);
return controlPanel;
}
private void buildPanel() {
JPanel tilePanel = new JPanel();
tilePanel.setBackground(Color.GRAY);
tilePanel.setLayout(new GridBagLayout());
GridBagConstraints constraints = new GridBagConstraints();
constraints.fill = GridBagConstraints.NONE;
constraints.gridx = 0;
constraints.gridy = 0;
constraints.weightx = 1;
constraints.weighty = 1;
for (TileType tileType : TileType.enabledTiles()) {
TileQuantityPanel quantityPanel = new TileQuantityPanel(tileType, distribution.getQuantity(tileType));
quantityPanels.add(quantityPanel);
tilePanel.add(quantityPanel, constraints);
constraints.gridx++;
if (constraints.gridx >= GRID_WIDTH) {
constraints.gridx = 0;
constraints.gridy++;
}
}
buildButtons(tilePanel, constraints);
getContentPane().add(tilePanel);
}
Item(Color backgroundColor, int preferredHeight, JComponent innerPanel) {
this.backgroundColor = backgroundColor;
this.preferredHeight = preferredHeight;
this.innerPanel = innerPanel;
topGapPanel = createGapPanel();
bottomGapPanel = createGapPanel();
separator = createSeparator();
outerPanel = new JPanel();
outerPanel.setBackground(backgroundColor);
outerPanel.setLayout(new BorderLayout());
outerPanel.add(BorderLayout.NORTH, topGapPanel);
outerPanel.add(BorderLayout.CENTER, innerPanel);
outerPanel.add(BorderLayout.SOUTH, bottomGapPanel);
outerPanel.setPreferredSize(new Dimension(0, preferredHeight));
scrollPane = new JScrollPane();
scrollPane.setBorder(new EmptyBorder(0, 0, 0, 0));
scrollPane.setPreferredSize(new Dimension(0, preferredHeight));
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
scrollPane.setViewportView(outerPanel);
}
private static JPanel createBox(final Color color, final Consumer<Color> consumer, final boolean alphaHidden)
{
final JPanel box = new JPanel();
String hex = alphaHidden ? ColorUtil.colorToHexCode(color) : ColorUtil.colorToAlphaHexCode(color);
box.setBackground(color);
box.setOpaque(true);
box.setPreferredSize(new Dimension(BOX_SIZE, BOX_SIZE));
box.setToolTipText("#" + hex.toUpperCase());
box.addMouseListener(new MouseAdapter()
{
@Override
public void mouseClicked(MouseEvent e)
{
consumer.accept(color);
}
});
return box;
}
public void fillWithSummaryTitles(JPanel gridPanel, StatKey prefixKey, List<CounterReportTemplate> templateList) {
// Panel for titles of all cols
JPanel panelTmp = new JPanel();
// Color of this panel
panelTmp.setBackground(ModelTreeRTStats.instance().getColorByString("columnTitle"));
// We want a text alignment on the left
panelTmp.setLayout(new javax.swing.BoxLayout(panelTmp, javax.swing.BoxLayout.X_AXIS));
// First column
panelTmp.add(new JLabel("<html>Summary</html>"));
// We add this panel to the main panel for shorts stats
gridPanel.add(panelTmp);
// For each template
for (CounterReportTemplate template : templateList) {
// Others columns
JPanel panelTmp2 = new JPanel();
// Color of this panel
panelTmp2.setBackground(ModelTreeRTStats.instance().getColorByString("columnTitle"));
// We want a text alignment on the left
panelTmp2.setLayout(new javax.swing.BoxLayout(panelTmp2, javax.swing.BoxLayout.X_AXIS));
// We add to this panel short descr of each template
panelTmp2.add(new JLabel("<html>" + template.summary + "</html>"));
// We add a toolTip on head section
panelTmp2.setToolTipText(template.name);
// We add this panel to the main panel for shorts stats
gridPanel.add(panelTmp2);
}
}
public ValidationErrorsBalloonView() {
panelMessages = new JPanel(new VerticalLayout(3, VerticalLayout.BOTH, VerticalLayout.TOP));
panelMessages.setBackground(errorBackgroundColor);
panelMessages.setOpaque(true);
balloonStyle = new RoundedBalloonStyle(5, 5, errorBackgroundColor, new Color(255, 0, 0));
}
public void init() {
JButton button = new JButton("Button"); // NON-NLS: the button text
button.setBorder(BorderFactory.createLineBorder(Color.red, 1));
TitledBorder border = new TitledBorder("Bordered Pane"); // NON-NLS: the panel title
border.setTitlePosition(TitledBorder.BELOW_BOTTOM);
JPanel panel = create(button, border);
panel.setBackground(Color.green);
getContentPane().add(create(panel, BorderFactory.createEmptyBorder(10, 10, 10, 10)));
}
public ThumbnailList()
{
metaDataEntries = new ArrayList<MetaData>();
content = new JPanel();
content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));
// thumbnailScrollPane = new JScrollPane(content);
content.setBackground(new Color(133,133,133));
this.setViewportView(content);
this.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
this.setBorder(BorderFactory.createLineBorder(Color.BLACK));
}
protected JComponent createComponent() {
component = new JPanel(new BorderLayout());
component.setOpaque(true);
component.setBackground(UIUtils.getProfilerResultsBackground());
objectsView.getComponent().setVisible(false); // force init in showObjectsView()
showObjectsView();
return component;
}
private static void createAndShowGUI() {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setBackground(Color.BLUE);
radioButton = new JRadioButton();
radioButton.setOpaque(false);
JPanel panel = new JPanel();
panel.setBackground(Color.BLUE);
panel.add(radioButton);
frame.getContentPane().add(panel);
frame.pack();
frame.setVisible(true);
}
private static void createAndShowUI() {
frame = new JFrame();
frame.setBounds(10, scrTop + 10, 300, 100);
JPanel panel = new JPanel();
panel.setBackground(color);
frame.getContentPane().add(panel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
private void initComponents() {
setLayout(new BorderLayout());
JPanel contentsPanel = new JPanel(new BorderLayout());
contentsPanel.setBackground(UIUtils.getProfilerResultsBackground());
contentsPanel.setOpaque(true);
contentsPanel.setBorder(BorderFactory.createMatteBorder(0, 15, 15, 15, UIUtils.getProfilerResultsBackground()));
headerArea = new HTMLTextArea() {
protected void showURL(URL url) {
String urlString = url.toString();
if (START_LOCATION_URLMASK.equals(urlString)) {
Utils.openLocation(LoadGenProfilingPoint.this.getStartLocation());
} else if (LoadGenProfilingPoint.this.usesEndLocation()) {
Utils.openLocation(LoadGenProfilingPoint.this.getEndLocation());
}
}
};
JScrollPane headerAreaScrollPane = new JScrollPane(headerArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
headerAreaScrollPane.setBorder(BorderFactory.createMatteBorder(0, 0, 15, 0, UIUtils.getProfilerResultsBackground()));
headerAreaScrollPane.setViewportBorder(BorderFactory.createEmptyBorder());
contentsPanel.add(headerAreaScrollPane, BorderLayout.NORTH);
dataArea = new HTMLTextArea();
JScrollPane dataAreaScrollPane = new JScrollPane(dataArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
TitledBorder tb = new TitledBorder(Bundle.LoadGenProfilingPoint_DataString());
tb.setTitleFont(Utils.getTitledBorderFont(tb).deriveFont(Font.BOLD));
tb.setTitleColor(javax.swing.UIManager.getColor("Label.foreground")); // NOI18N
dataAreaScrollPane.setBorder(tb);
dataAreaScrollPane.setViewportBorder(BorderFactory.createEmptyBorder());
dataAreaScrollPane.setBackground(UIUtils.getProfilerResultsBackground());
contentsPanel.add(dataAreaScrollPane, BorderLayout.CENTER);
add(contentsPanel, BorderLayout.CENTER);
}
@NotNull
private JComponent createHintComponent(@NotNull String text,
@NotNull final FindUsagesHandler handler, @NotNull final RelativePoint popupPosition,
final Editor editor, @NotNull final Runnable cancelAction, final int maxUsages,
@NotNull final FindUsagesOptions options) {
JComponent label =
HintUtil.createInformationLabel(suggestSecondInvocation(options, handler, text + " "));
InplaceButton button =
createSettingsButton(handler, popupPosition, editor, maxUsages, cancelAction);
JPanel panel = new JPanel(new BorderLayout()) {
@Override
public void addNotify() {
mySearchEverywhereRunnable = new Runnable() {
@Override
public void run() {
searchEverywhere(options, handler, editor, popupPosition, maxUsages);
}
};
super.addNotify();
}
@Override
public void removeNotify() {
mySearchEverywhereRunnable = null;
super.removeNotify();
}
};
button.setBackground(label.getBackground());
panel.setBackground(label.getBackground());
label.setOpaque(false);
label.setBorder(null);
panel.setBorder(HintUtil.createHintBorder());
panel.add(label, BorderLayout.CENTER);
panel.add(button, BorderLayout.EAST);
return panel;
}
public ImageScroller(Icon icon) {
super();
setBorder(null);
JPanel p = new JPanel();
p.setBorder(null);
// p.setOpaque(false);
p.setBackground(Color.white);
p.setLayout(new BorderLayout());
p.add(new JLabel(icon), BorderLayout.CENTER);
getViewport().add(p);
getHorizontalScrollBar().setUnitIncrement(10);
getVerticalScrollBar().setUnitIncrement(10);
}
public FastpathContainer() {
setLayout(new GridBagLayout());
topPanel = new JPanel();
mainPanel = new SparkTabbedPane();
add(topPanel, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(2, 2, 0, 2), 0, 0));
add(mainPanel, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(2, 2, 0, 2), 0, 0));
topPanel.setLayout(new BorderLayout());
mainPanel.setBackground(Color.white);
topPanel.setBackground(Color.white);
setBackground(Color.white);
mainPanel.getMainPanel().setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY, 1));
mainPanel.getMainPanel().setBackground(Color.white);
}
/**
* @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable,
* java.lang.Object, boolean, boolean, int, int)
*/
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
boolean hasFocus, int row, int column) {
JPanel newPanel = new JPanel();
newPanel.setLayout(new OverlayLayout(newPanel));
Color bgColor;
if (isSelected)
bgColor = table.getSelectionBackground();
else
bgColor = table.getBackground();
newPanel.setBackground(bgColor);
if (hasFocus) {
Border border = null;
if (isSelected)
border = UIManager.getBorder("Table.focusSelectedCellHighlightBorder");
if (border == null)
border = UIManager.getBorder("Table.focusCellHighlightBorder");
if (border != null)
newPanel.setBorder(border);
}
if (value != null) {
if (value instanceof JComponent) {
newPanel.add((JComponent) value);
} else {
JLabel newLabel = new JLabel();
if (value instanceof IIsotope) {
IIsotope is = (IIsotope) value;
newLabel.setText(is.getSymbol());
} else {
newLabel.setText(value.toString());
}
if (font != null)
newLabel.setFont(font);
else if (table.getFont() != null)
newLabel.setFont(table.getFont());
newPanel.add(newLabel);
}
if (createTooltips)
newPanel.setToolTipText(value.toString());
}
return newPanel;
}
private JPanel createPanTableHeader(){
dateChooser = CalendarChooser.getDateChooser();
JPanel dateChooserPanel = dateChooser.getChooser();
JPanel headerPanel = new JPanel(new BorderLayout());
JLabel label = new JLabel(DisplayStrings.DATE_STR.toString());
label.setFont(UIUtil.getFont());
headerPanel.add(label, BorderLayout.WEST);
headerPanel.add(dateChooserPanel, BorderLayout.EAST);
headerPanel.setBorder(BorderFactory.createEtchedBorder());
label.setPreferredSize(new Dimension(KeyColWidth , RowHeight));
dateChooserPanel.setPreferredSize(new Dimension(ValueColWidth , RowHeight));
headerPanel.setPreferredSize(headerSize);
headerPanel.setBackground(UIConsts.TABLE_HEADER_BACKGROUND);
label.setForeground(UIConsts.TABLE_HEADER_FOREGROUND);
dateChooser.setBackground(UIConsts.TABLE_HEADER_BACKGROUND);
dateChooser.setForeground(UIConsts.TABLE_HEADER_FOREGROUND);
dateChooser.setSelectedDate(pan.getDate().getTime());
JPanel outerPanel = new JPanel();
outerPanel.add(headerPanel);
return outerPanel;
}
public DialPanel() {
setLayout(new GridBagLayout());
JPanel imagePanel = new JPanel();
imagePanel.setLayout(new BorderLayout());
imagePanel.setBackground(Color.white);
iconLabel = new JLabel(SparkRes.getImageIcon(SparkRes.TELEPHONE_24x24));
iconLabel.setHorizontalAlignment(JLabel.CENTER);
iconLabel.setVerticalTextPosition(JLabel.BOTTOM);
iconLabel.setHorizontalTextPosition(JLabel.CENTER);
imagePanel.add(iconLabel, BorderLayout.CENTER);
iconLabel.setFont(new Font("Dialog", Font.BOLD, 14));
dialPanel.setLayout(new GridBagLayout());
JLabel dialLabel = new JLabel();
dialPanel.add(dialLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.WEST, new Insets(5, 5, 5, 5), 0, 0));
dialField = new JTextField();
dialPanel.add(dialField, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
dialButton = new JButton("");
dialPanel.add(dialButton, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.WEST, new Insets(5, 5, 5, 5), 0, 0));
add(imagePanel, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
add(dialPanel, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
iconLabel.setText(Res.getString("title.waiting.to.call"));
ResourceUtils.resButton(dialButton, Res.getString("label.dial"));
ResourceUtils.resLabel(dialLabel, dialField, Res.getString("label.number") + ":");
}