下面列出了javax.swing.SwingConstants#BOTTOM 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
protected void paintComponent(Graphics graphics) {
graphics.setColor(getBackground());
graphics.fillRect(0, 0, getWidth(), getHeight());
switch (imageAlign) {
case (SwingConstants.TOP):
graphics.drawImage(image, (getWidth() - image.getWidth(null)) / 2, 0, this);
break;
case (SwingConstants.BOTTOM):
graphics.drawImage(image, (getWidth() - image.getWidth(null)) / 2, getHeight() - image.getHeight(null), this);
break;
default:
graphics.drawImage(image, (getWidth() - image.getWidth(null)) / 2, 0, this);
}
}
private void setupUI(Style style) {
size.getEditor().setItem(style.font.getSize() + "");
bold.setSelected((style.font.getStyle() & Font.BOLD) != 0);
italic.setSelected((style.font.getStyle() & Font.ITALIC) != 0);
selectFont(style.font.getFamily());
switch(style.vAlign) {
case SwingConstants.TOP: anorth.setSelected(true); break;
case SwingConstants.CENTER: acenterv.setSelected(true); break;
case SwingConstants.BOTTOM: asouth.setSelected(true); break;
}
switch(style.hAlign) {
case SwingConstants.LEFT: awest.setSelected(true); break;
case SwingConstants.CENTER: acenterh.setSelected(true); break;
case SwingConstants.RIGHT: aeast.setSelected(true); break;
}
}
protected void paintComponent(Graphics graphics) {
graphics.setColor(getBackground());
graphics.fillRect(0, 0, getWidth(), getHeight());
switch (imageAlign) {
case (SwingConstants.TOP):
graphics.drawImage(image, (getWidth() - image.getWidth(null)) / 2, 0, this);
break;
case (SwingConstants.BOTTOM):
graphics.drawImage(image, (getWidth() - image.getWidth(null)) / 2, getHeight() - image.getHeight(null), this);
break;
default:
graphics.drawImage(image, (getWidth() - image.getWidth(null)) / 2, 0, this);
}
}
protected GradientPaint createContentGradient(JComponent c,
boolean isSelected) {
JTabbedPane tabs = getTabbedPaneParent(c);
int placement = tabs == null ? SwingConstants.TOP : tabs
.getTabPlacement();
Color outer = isSelected ? contentOuterSelected
: contentOuterNormal;
Color inner = isSelected ? contentInnerSelected
: contentInnerNormal;
if (placement == SwingConstants.LEFT) {
return (new GradientPaint(0, 0, outer, c.getWidth(), 0, inner));
} else if (placement == SwingConstants.RIGHT) {
return (new GradientPaint(0, 0, inner, c.getWidth(), 0, outer));
} else if (placement == SwingConstants.BOTTOM) {
return (new GradientPaint(0, 0, inner, 0, c.getHeight(), outer));
} else {
return (new GradientPaint(0, 0, outer, 0, c.getHeight(), inner));
}
}
@Override
public void formatControlRow(JTabbedPane tabs, JPanel tabsContainer) {
Border border;
Paint paint = createBorderGradient(tabs.getTabPlacement());
if (tabs.getTabPlacement() == SwingConstants.BOTTOM) {
border = new PartialLineBorder(paint, true, true,
tabs.getTabCount() == 0, true);
} else if (tabs.getTabPlacement() == SwingConstants.LEFT) {
border = new PartialLineBorder(paint, true,
tabs.getTabCount() == 0, true, true);
} else if (tabs.getTabPlacement() == SwingConstants.RIGHT) {
border = new PartialLineBorder(paint, true, true, true,
tabs.getTabCount() == 0);
} else {
border = new PartialLineBorder(paint, tabs.getTabCount() == 0,
true, true, true);
}
tabsContainer.setUI(new GradientPanelUI(createContentGradient(tabs,
false)));
tabsContainer.setBorder(border);
}
@Override
public void formatTabContent(JTabbedPane tabs, JComponent c) {
if (contentBorder) {
Border border;
if (tabs.getTabPlacement() == SwingConstants.LEFT) {
border = new PartialLineBorder(borderNormalDark, true,
false, true, true);
} else if (tabs.getTabPlacement() == SwingConstants.BOTTOM) {
border = new PartialLineBorder(borderNormalDark, true,
true, false, true);
} else if (tabs.getTabPlacement() == SwingConstants.RIGHT) {
border = new PartialLineBorder(borderNormalDark, true,
true, true, false);
} else {
border = new PartialLineBorder(borderNormalDark, false,
true, true, true);
}
c.setBorder(border);
}
}
@Override
protected void installDefaults() {
super.installDefaults();
separatorColor = UIManager.getColor( "TableHeader.separatorColor" );
bottomSeparatorColor = UIManager.getColor( "TableHeader.bottomSeparatorColor" );
height = UIManager.getInt( "TableHeader.height" );
switch( Objects.toString( UIManager.getString( "TableHeader.sortIconPosition" ), "right" ) ) {
default:
case "right": sortIconPosition = SwingConstants.RIGHT; break;
case "left": sortIconPosition = SwingConstants.LEFT; break;
case "top": sortIconPosition = SwingConstants.TOP; break;
case "bottom": sortIconPosition = SwingConstants.BOTTOM; break;
}
}
/**
* Updates the location of <code>this</code> tab overview button.
*
* @param tabbedPane
* Tabbed pane.
* @param tabAreaInsets
* Tab area insets.
*/
public void updateLocation(JTabbedPane tabbedPane, Insets tabAreaInsets) {
if (tabbedPane == null)
return;
// Lock the button for the bounds change
this.putClientProperty(TabOverviewButton.OWN_BOUNDS, Boolean.TRUE);
int buttonSize = SubstanceSizeUtils.getLookupButtonSize();
switch (tabbedPane.getTabPlacement()) {
case SwingConstants.TOP:
if (tabbedPane.getComponentOrientation().isLeftToRight())
this.setBounds(2, tabAreaInsets.top, buttonSize, buttonSize);
else
this.setBounds(tabbedPane.getBounds().width - tabAreaInsets.right - buttonSize - 2,
tabAreaInsets.top, buttonSize, buttonSize);
break;
case SwingConstants.BOTTOM:
if (tabbedPane.getComponentOrientation().isLeftToRight())
this.setBounds(2,
tabbedPane.getBounds().height - tabAreaInsets.bottom - buttonSize - 4,
buttonSize, buttonSize);
else
this.setBounds(tabbedPane.getBounds().width - tabAreaInsets.right - buttonSize - 2,
tabbedPane.getBounds().height - tabAreaInsets.bottom - buttonSize - 4,
buttonSize, buttonSize);
break;
case SwingConstants.LEFT:
this.setBounds(2, tabAreaInsets.top - 1, buttonSize, buttonSize);
break;
case SwingConstants.RIGHT:
this.setBounds(tabbedPane.getBounds().width - tabAreaInsets.right - buttonSize - 2,
tabAreaInsets.top - 1, buttonSize, buttonSize);
break;
}
// Unlock the button for the bounds change
this.putClientProperty(TabOverviewButton.OWN_BOUNDS, null);
}
/**
* Create the left side panel of the client.
*
* @return A component containing the components left of the game screen
*/
private JComponent createLeftPanel(StendhalClient client) {
minimap = new MapPanelController(client);
final StatsPanelController stats = StatsPanelController.get();
final BuddyPanelController buddies = BuddyPanelController.get();
ScrolledViewport buddyScroll = new ScrolledViewport((JComponent) buddies.getComponent());
buddyScroll.setScrollingSpeed(SCROLLING_SPEED);
final JComponent buddyPane = buddyScroll.getComponent();
buddyPane.setBorder(null);
final JComponent leftColumn = SBoxLayout.createContainer(SBoxLayout.VERTICAL);
leftColumn.add(minimap.getComponent(), SLayout.EXPAND_X);
leftColumn.add(stats.getComponent(), SLayout.EXPAND_X);
// Add a background for the tabs. The column itself has none.
JPanel tabBackground = new JPanel();
tabBackground.setBorder(null);
tabBackground.setLayout(new SBoxLayout(SBoxLayout.VERTICAL));
JTabbedPane tabs = new JTabbedPane(SwingConstants.BOTTOM);
// Adjust the Tab Width, if we can. The default is pretty if there's
// space, but in the column there are no pixels to waste.
TabbedPaneUI ui = tabs.getUI();
if (ui instanceof StyledTabbedPaneUI) {
((StyledTabbedPaneUI) ui).setTabLabelMargins(1);
}
tabs.setFocusable(false);
tabs.add("Friends", buddyPane);
tabs.add("Group", GroupPanelController.get().getComponent());
tabBackground.add(tabs, SBoxLayout.constraint(SLayout.EXPAND_X, SLayout.EXPAND_Y));
leftColumn.add(tabBackground, SBoxLayout.constraint(SLayout.EXPAND_X, SLayout.EXPAND_Y));
return leftColumn;
}
@Override
public void setBounds(final Rectangle BOUNDS) {
if (BOUNDS.width <= BOUNDS.height) {
// vertical
int yNew;
switch(verticalAlignment) {
case SwingConstants.TOP:
yNew = BOUNDS.y;
break;
case SwingConstants.BOTTOM:
yNew = BOUNDS.y + (BOUNDS.height - BOUNDS.width);
break;
case SwingConstants.CENTER:
default:
yNew = BOUNDS.y + ((BOUNDS.height - BOUNDS.width) / 2);
break;
}
super.setBounds(BOUNDS.x, yNew, BOUNDS.width, BOUNDS.width);
} else {
// horizontal
int xNew;
switch(horizontalAlignment) {
case SwingConstants.LEFT:
xNew = BOUNDS.x;
break;
case SwingConstants.RIGHT:
xNew = BOUNDS.x + (BOUNDS.width - BOUNDS.height);
break;
case SwingConstants.CENTER:
default:
xNew = BOUNDS.x + ((BOUNDS.width - BOUNDS.height) / 2);
break;
}
super.setBounds(xNew, BOUNDS.y, BOUNDS.height, BOUNDS.height);
}
calcInnerBounds();
init(getGaugeBounds().width, getGaugeBounds().height);
setInitialized(true);
}
private GradientPaint createBorderGradient(int tabPlacement) {
if (tabPlacement == SwingConstants.BOTTOM) {
return new GradientPaint(0, 0, borderNormalDark, 0, 25,
borderNormalLight);
} else if (tabPlacement == SwingConstants.LEFT) {
return new GradientPaint(0, 0, borderNormalLight, 25, 0,
borderNormalDark);
} else if (tabPlacement == SwingConstants.RIGHT) {
return new GradientPaint(0, 0, borderNormalDark, 25, 0,
borderNormalLight);
} else {
return new GradientPaint(0, 0, borderNormalLight, 0, 25,
borderNormalDark);
}
}
@Override
public void setBounds(final Rectangle BOUNDS) {
if (BOUNDS.width <= BOUNDS.height) {
// vertical
int yNew;
switch(verticalAlignment) {
case SwingConstants.TOP:
yNew = BOUNDS.y;
break;
case SwingConstants.BOTTOM:
yNew = BOUNDS.y + (BOUNDS.height - BOUNDS.width);
break;
case SwingConstants.CENTER:
default:
yNew = BOUNDS.y + ((BOUNDS.height - BOUNDS.width) / 2);
break;
}
super.setBounds(BOUNDS.x, yNew, BOUNDS.width, BOUNDS.width);
} else {
// horizontal
int xNew;
switch(horizontalAlignment) {
case SwingConstants.LEFT:
xNew = BOUNDS.x;
break;
case SwingConstants.RIGHT:
xNew = BOUNDS.x + (BOUNDS.width - BOUNDS.height);
break;
case SwingConstants.CENTER:
default:
xNew = BOUNDS.x + ((BOUNDS.width - BOUNDS.height) / 2);
break;
}
super.setBounds(xNew, BOUNDS.y, BOUNDS.height, BOUNDS.height);
}
calcInnerBounds();
init(INNER_BOUNDS.width, INNER_BOUNDS.height);
}
@Override
public void setBounds(final int X, final int Y, final int WIDTH, final int HEIGHT) {
if (WIDTH <= HEIGHT) {
// vertical
int yNew;
switch(verticalAlignment) {
case SwingConstants.TOP:
yNew = Y;
break;
case SwingConstants.BOTTOM:
yNew = Y + (HEIGHT - WIDTH);
break;
case SwingConstants.CENTER:
default:
yNew = Y + ((HEIGHT - WIDTH) / 2);
break;
}
super.setBounds(X, yNew, WIDTH, WIDTH);
} else {
// horizontal
int xNew;
switch(horizontalAlignment) {
case SwingConstants.LEFT:
xNew = X;
break;
case SwingConstants.RIGHT:
xNew = X + (WIDTH - HEIGHT);
break;
case SwingConstants.CENTER:
default:
xNew = X + ((WIDTH - HEIGHT) / 2);
break;
}
super.setBounds(xNew, Y, HEIGHT, HEIGHT);
}
calcInnerBounds();
init(INNER_BOUNDS.width, INNER_BOUNDS.height);
}
@Override
public void setBounds(final Rectangle BOUNDS) {
if (BOUNDS.width <= BOUNDS.height) {
// vertical
int yNew;
switch(verticalAlignment) {
case SwingConstants.TOP:
yNew = BOUNDS.y;
break;
case SwingConstants.BOTTOM:
yNew = BOUNDS.y + (BOUNDS.height - BOUNDS.width);
break;
case SwingConstants.CENTER:
default:
yNew = BOUNDS.y + ((BOUNDS.height - BOUNDS.width) / 2);
break;
}
super.setBounds(BOUNDS.x, yNew, BOUNDS.width, BOUNDS.width);
} else {
// horizontal
int xNew;
switch(horizontalAlignment) {
case SwingConstants.LEFT:
xNew = BOUNDS.x;
break;
case SwingConstants.RIGHT:
xNew = BOUNDS.x + (BOUNDS.width - BOUNDS.height);
break;
case SwingConstants.CENTER:
default:
xNew = BOUNDS.x + ((BOUNDS.width - BOUNDS.height) / 2);
break;
}
super.setBounds(xNew, BOUNDS.y, BOUNDS.height, BOUNDS.height);
}
calcInnerBounds();
init(getGaugeBounds().width, getGaugeBounds().height);
setInitialized(true);
}
@Override
public void setBounds(final int X, final int Y, final int WIDTH, final int HEIGHT) {
if (WIDTH <= HEIGHT) {
// vertical
int yNew;
switch(verticalAlignment) {
case SwingConstants.TOP:
yNew = Y;
break;
case SwingConstants.BOTTOM:
yNew = Y + (HEIGHT - WIDTH);
break;
case SwingConstants.CENTER:
default:
yNew = Y + ((HEIGHT - WIDTH) / 2);
break;
}
super.setBounds(X, yNew, WIDTH, WIDTH);
} else {
// horizontal
int xNew;
switch(horizontalAlignment) {
case SwingConstants.LEFT:
xNew = X;
break;
case SwingConstants.RIGHT:
xNew = X + (WIDTH - HEIGHT);
break;
case SwingConstants.CENTER:
default:
xNew = X + ((WIDTH - HEIGHT) / 2);
break;
}
super.setBounds(xNew, Y, HEIGHT, HEIGHT);
}
calcInnerBounds();
init(getGaugeBounds().width, getGaugeBounds().height);
setInitialized(true);
}
@Override
public void setBounds(final int X, final int Y, final int WIDTH, final int HEIGHT) {
if (WIDTH <= HEIGHT) {
// vertical
int yNew;
switch(verticalAlignment) {
case SwingConstants.TOP:
yNew = Y;
break;
case SwingConstants.BOTTOM:
yNew = Y + (HEIGHT - WIDTH);
break;
case SwingConstants.CENTER:
default:
yNew = Y + ((HEIGHT - WIDTH) / 2);
break;
}
super.setBounds(X, yNew, WIDTH, WIDTH);
} else {
// horizontal
int xNew;
switch(horizontalAlignment) {
case SwingConstants.LEFT:
xNew = X;
break;
case SwingConstants.RIGHT:
xNew = X + (WIDTH - HEIGHT);
break;
case SwingConstants.CENTER:
default:
xNew = X + ((WIDTH - HEIGHT) / 2);
break;
}
super.setBounds(xNew, Y, HEIGHT, HEIGHT);
}
calcInnerBounds();
init(INNER_BOUNDS.width);
initialized = true;
}
@Override
public void setBounds(final Rectangle BOUNDS) {
if (BOUNDS.width <= BOUNDS.height) {
// vertical
int yNew;
switch(verticalAlignment) {
case SwingConstants.TOP:
yNew = BOUNDS.y;
break;
case SwingConstants.BOTTOM:
yNew = BOUNDS.y + (BOUNDS.height - BOUNDS.width);
break;
case SwingConstants.CENTER:
default:
yNew = BOUNDS.y + ((BOUNDS.height - BOUNDS.width) / 2);
break;
}
super.setBounds(BOUNDS.x, yNew, BOUNDS.width, BOUNDS.width);
} else {
// horizontal
int xNew;
switch(horizontalAlignment) {
case SwingConstants.LEFT:
xNew = BOUNDS.x;
break;
case SwingConstants.RIGHT:
xNew = BOUNDS.x + (BOUNDS.width - BOUNDS.height);
break;
case SwingConstants.CENTER:
default:
xNew = BOUNDS.x + ((BOUNDS.width - BOUNDS.height) / 2);
break;
}
super.setBounds(xNew, BOUNDS.y, BOUNDS.height, BOUNDS.height);
}
calcInnerBounds();
init(getGaugeBounds().width, getGaugeBounds().height);
setInitialized(true);
}
@Override
public void setBounds(final int X, final int Y, final int WIDTH, final int HEIGHT) {
if (WIDTH <= HEIGHT) {
// vertical
int yNew;
switch(verticalAlignment) {
case SwingConstants.TOP:
yNew = Y;
break;
case SwingConstants.BOTTOM:
yNew = Y + (HEIGHT - WIDTH);
break;
case SwingConstants.CENTER:
default:
yNew = Y + ((HEIGHT - WIDTH) / 2);
break;
}
super.setBounds(X, yNew, WIDTH, WIDTH);
} else {
// horizontal
int xNew;
switch(horizontalAlignment) {
case SwingConstants.LEFT:
xNew = X;
break;
case SwingConstants.RIGHT:
xNew = X + (WIDTH - HEIGHT);
break;
case SwingConstants.CENTER:
default:
xNew = X + ((WIDTH - HEIGHT) / 2);
break;
}
super.setBounds(xNew, Y, HEIGHT, HEIGHT);
}
calcInnerBounds();
init(getGaugeBounds().width, getGaugeBounds().height);
setInitialized(true);
}
private static WebPanel createListPanel(final WebTable list,
String overlayText,
WebToggleButton button) {
// overlay for empty list
WebOverlay listOverlay = new WebOverlay(list);
listOverlay.setOverlayMargin(20);
final WebTextArea overlayArea = new WebTextArea();
overlayArea.setText(overlayText);
overlayArea.setLineWrap(true);
overlayArea.setWrapStyleWord(true);
overlayArea.setMargin(View.MARGIN_DEFAULT);
overlayArea.setFontSize(View.FONT_SIZE_BIG);
overlayArea.setEditable(false);
BorderPainter<WebTextArea> borderPainter = new BorderPainter<>(Color.LIGHT_GRAY);
borderPainter.setRound(15);
overlayArea.setPainter(borderPainter);
list.getModel().addTableModelListener(new TableModelListener() {
@Override
public void tableChanged(TableModelEvent e) {
overlayArea.setVisible(list.getModel().getRowCount() == 0);
}
});
overlayArea.setVisible(list.getModel().getRowCount() == 0);
listOverlay.addOverlay(overlayArea, SwingConstants.CENTER, SwingConstants.CENTER);
WebScrollPane scrollPane = new ComponentUtils.ScrollPane(listOverlay);
scrollPane.setDrawBorder(false);
// button as overlay
button.setOpaque(false);
button.setUndecorated(true);
WebOverlay chatListOverlay = new WebOverlay(scrollPane,
button, SwingConstants.TRAILING, SwingConstants.BOTTOM);
chatListOverlay.setOverlayMargin(0, 0, View.GAP_BIG, View.GAP_BIG + SCROLL_BAR_WIDTH);
// fixing overlay button paint bug on startup, dont wanna know whats happening here
SwingUtils.delayInvokeLater(0, new Runnable() {
@Override
public void run() {
TooltipManager.showOneTimeTooltip(list, new Point(1,1), "");
}
});
return chatListOverlay;
}
static boolean validVerticalKey(int key) {
return ((key == SwingConstants.TOP) || (key == SwingConstants.CENTER) || (key == SwingConstants.BOTTOM));
}