下面列出了怎么用javax.swing.border.EmptyBorder的API类实例代码及写法,或者点击链接到github查看源代码。
private void setStyle(Style style)
{
container.removeAll();
if (style == Style.SIMPLE)
{
progressWrapper.setBorder(new EmptyBorder(7, 7, 7, 7));
container.add(skillWrapper, BorderLayout.WEST);
container.add(progressWrapper, BorderLayout.CENTER);
}
else
{
progressWrapper.setBorder(new EmptyBorder(4, 7, 7, 7));
container.add(skillWrapper, BorderLayout.WEST);
container.add(statsPanel, BorderLayout.CENTER);
container.add(progressWrapper, BorderLayout.SOUTH);
}
panel.revalidate();
this.style = style;
}
/**
* Builds the world list field (containing the country's flag and the world index).
*/
private JPanel buildWorldField()
{
JPanel column = new JPanel(new BorderLayout(7, 0));
column.setBorder(new EmptyBorder(0, 5, 0, 5));
worldField = new JLabel(world.getId() + "");
ImageIcon flagIcon = getFlag(world.getRegion());
if (flagIcon != null)
{
JLabel flag = new JLabel(flagIcon);
column.add(flag, BorderLayout.WEST);
}
column.add(worldField, BorderLayout.CENTER);
return column;
}
private JPanel create() {
recentChoices = new GhidraComboBox<>();
recentChoices.setEditable(true);
JPanel mainPanel = new JPanel(new BorderLayout());
JPanel topPanel = new JPanel(new BorderLayout());
Border border = BorderFactory.createTitledBorder("Data Field Name");
topPanel.setBorder(border);
mainPanel.add(topPanel, BorderLayout.NORTH);
topPanel.add(recentChoices, BorderLayout.NORTH);
choiceTextField = (JTextField)recentChoices.getEditor().getEditorComponent();
setFocusComponent(choiceTextField);
choiceTextField.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
okCallback();
}
});
mainPanel.setBorder(new EmptyBorder(5,5,5,5));
return mainPanel;
}
@Override
public void installComponents(final JFileChooser fc) {
fc.setBorder(new EmptyBorder(10, 10, 7, 10));
fc.setLayout(new BorderLayout(0, 7));
filePane = createFilePane(fc);
fc.add(createTopPanel(fc), BorderLayout.NORTH);
fc.add(filePane, BorderLayout.CENTER);
fc.add(createBottomPanel(fc), BorderLayout.SOUTH);
fc.add(createControlPanel(fc), BorderLayout.AFTER_LINE_ENDS);
setupButtonPanel(fc);
if (fc.getControlButtonsAreShown()) {
addControlButtons();
}
groupLabels(new AlignedLabel[]{fileNameLabel, filesOfTypeLabel});
}
@Override
protected void installDefaults() {
if( group.getContentPane() instanceof JComponent ) {
// remove default SwingX content border, which may be still set when switching LaF
JComponent content = (JComponent) group.getContentPane();
Border contentBorder = content.getBorder();
if( contentBorder instanceof CompoundBorder &&
((CompoundBorder)contentBorder).getOutsideBorder() instanceof BasicTaskPaneUI.ContentPaneBorder &&
((CompoundBorder)contentBorder).getInsideBorder() instanceof EmptyBorder )
{
content.setBorder( null );
}
// set non-UIResource color to background to avoid that it is lost when switching LaF
background = UIManager.getColor( "TaskPane.background" );
Color bg = content.getBackground();
if( bg == null || bg instanceof UIResource ) {
content.setBackground( new Color( background.getRGB(), true ) );
}
}
roundHeight = FlatUIUtils.getUIInt( "TaskPane.roundHeight", UIManager.getInt( "Component.arc" ) );
super.installDefaults();
}
private JComponent buildMainPanel() {
Border panelBorder = new EmptyBorder(5, 10, 5, 10);
if (externalLocation != null) {
extLocPanel = new EditExternalLocationPanel(externalLocation); // Edit
}
else {
extLocPanel = new EditExternalLocationPanel(program, externalLibraryName); // Create
}
extLocPanel.setBorder(panelBorder);
int panelHeight = (externalLocation != null) ? PREFERRED_EDIT_PANEL_HEIGHT
: PREFERRED_CREATE_PANEL_HEIGHT;
extLocPanel.setPreferredSize(new Dimension(PREFERRED_PANEL_WIDTH, panelHeight));
JPanel workPanel = new JPanel(new BorderLayout());
workPanel.add(extLocPanel, BorderLayout.CENTER);
return workPanel;
}
SkillCalculatorPanel(SkillIconManager iconManager, Client client, SpriteManager spriteManager, ItemManager itemManager)
{
super();
getScrollPane().setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
this.iconManager = iconManager;
setBorder(new EmptyBorder(10, 10, 10, 10));
setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 1;
c.gridx = 0;
c.gridy = 0;
tabGroup = new MaterialTabGroup();
tabGroup.setLayout(new GridLayout(0, 6, 7, 7));
addCalculatorButtons();
final UICalculatorInputArea uiInput = new UICalculatorInputArea();
uiInput.setBorder(new EmptyBorder(15, 0, 15, 0));
uiInput.setBackground(ColorScheme.DARK_GRAY_COLOR);
uiCalculator = new SkillCalculator(client, uiInput, spriteManager, itemManager);
add(tabGroup, c);
c.gridy++;
add(uiInput, c);
c.gridy++;
add(uiCalculator, c);
c.gridy++;
}
BookPanel(final Book b)
{
setBorder(new EmptyBorder(3, 3, 3, 3));
setBackground(ColorScheme.DARK_GRAY_COLOR);
GroupLayout layout = new GroupLayout(this);
this.setLayout(layout);
JLabel image = new JLabel();
b.getIcon().addTo(image);
JLabel name = new JLabel(b.getShortName());
location.setFont(FontManager.getRunescapeSmallFont());
layout.setVerticalGroup(layout.createParallelGroup()
.addComponent(image)
.addGroup(layout.createSequentialGroup()
.addComponent(name)
.addComponent(location)
)
);
layout.setHorizontalGroup(layout.createSequentialGroup()
.addComponent(image)
.addGap(8)
.addGroup(layout.createParallelGroup()
.addComponent(name)
.addComponent(location)
)
);
// AWT's Z order is weird. This put image at the back of the stack
setComponentZOrder(image, getComponentCount() - 1);
}
void init()
{
setLayout(new BorderLayout(0, 5));
setBorder(new EmptyBorder(10, 10, 10, 10));
setBackground(ColorScheme.DARK_GRAY_COLOR);
JPanel books = new JPanel(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 1;
c.gridx = 0;
c.gridy = 0;
Stream.of(Book.values())
.filter(b -> !b.isDarkManuscript())
.filter(b -> !config.hideVarlamoreEnvoy() || b != Book.VARLAMORE_ENVOY)
.sorted(Comparator.comparing(Book::getShortName))
.forEach(b ->
{
BookPanel p = new BookPanel(b);
bookPanels.put(b, p);
books.add(p, c);
c.gridy++;
});
JButton reset = new JButton("Reset", RESET_ICON);
reset.setRolloverIcon(RESET_HOVER_ICON);
reset.addActionListener(ev ->
{
library.reset();
update();
});
add(reset, BorderLayout.NORTH);
add(books, BorderLayout.CENTER);
update();
}
protected TitledBorderUIResource getObject() {
return new TitledBorderUIResource(
new EmptyBorder(1, 2, 3, 4),
"TITLE",
TitledBorder.CENTER,
TitledBorder.ABOVE_TOP,
new Font("Serif", Font.ITALIC, 12),
Color.RED);
}
public static void main(String[] args) throws Exception {
for (UIManager.LookAndFeelInfo lookAndFeel : UIManager.getInstalledLookAndFeels()) {
for (Object[] defaultTitlePosition : DEFAULT_TITLE_POSITIONS) {
if (defaultTitlePosition[0].equals(lookAndFeel.getName())) {
UIManager.setLookAndFeel(lookAndFeel.getClassName());
final int expectedPosition = (Integer) defaultTitlePosition[1];
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
List<TitledBorder> borders = new ArrayList<>();
borders.add(BorderFactory.createTitledBorder(new EmptyBorder(0, 0, 0, 0), "Title"));
try {
Method getPositionMethod = TitledBorder.class.getDeclaredMethod("getPosition");
getPositionMethod.setAccessible(true);
for (TitledBorder border : borders) {
int position = (Integer) getPositionMethod.invoke(border);
if (position != expectedPosition) {
throw new RuntimeException("Invalid title position");
}
}
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
});
System.out.println("Test passed for LookAndFeel " + lookAndFeel.getName());
}
}
}
}
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();
}
ItemPanel(ItemDefinition item, KitType kitType, AsyncBufferedImage icon)
{
setBorder(new EmptyBorder(3, 3, 3, 3));
setBackground(ColorScheme.DARK_GRAY_COLOR);
GroupLayout layout = new GroupLayout(this);
this.setLayout(layout);
JLabel name = new JLabel(item.getName());
JLabel location = new JLabel(StringUtils.capitalize(kitType.toString().toLowerCase()));
location.setFont(FontManager.getRunescapeSmallFont());
JLabel imageLabel = new JLabel();
icon.addTo(imageLabel);
layout.setVerticalGroup(layout.createParallelGroup()
.addComponent(imageLabel)
.addGroup(layout.createSequentialGroup()
.addComponent(name)
.addComponent(location)
)
);
layout.setHorizontalGroup(layout.createSequentialGroup()
.addComponent(imageLabel)
.addGap(8)
.addGroup(layout.createParallelGroup()
.addComponent(name)
.addComponent(location)
)
);
// AWT's Z order is weird. This put image at the back of the stack
setComponentZOrder(imageLabel, getComponentCount() - 1);
}
/**
* Check behaviour of method TitledBorder.getTitleFont()
*/
private static void checkTitleFont() {
TitledBorder titledBorder = new TitledBorder(new EmptyBorder(1, 1, 1, 1));
Font defaultFont = UIManager.getLookAndFeelDefaults().getFont("TitledBorder.font");
Font titledBorderFont = titledBorder.getTitleFont();
// check default configuration
if (defaultFont == null) {
if (titledBorderFont == null) {
return;
}
else {
throw new RuntimeException("TitledBorder default font should be null");
}
}
if (!defaultFont.equals(titledBorderFont)) {
throw new RuntimeException("L&F default font " + defaultFont.toString()
+ " differs from TitledBorder font " + titledBorderFont.toString());
}
// title font is explicitly specified
Font font = new Font("Dialog", Font.PLAIN, 10);
titledBorder.setTitleFont(font);
if (!font.equals(titledBorder.getTitleFont())) {
throw new RuntimeException("TitledBorder font should be " + font.toString());
}
// title Font is unspecified
titledBorder.setTitleFont(null);
if (!defaultFont.equals(titledBorder.getTitleFont())) {
throw new RuntimeException("L&F default font " + defaultFont.toString()
+ " differs from TitledBorder font " + titledBorderFont.toString());
}
}
FeedPanel(FeedConfig config, Supplier<FeedResult> feedSupplier)
{
super(true);
this.config = config;
this.feedSupplier = feedSupplier;
setBorder(new EmptyBorder(10, 10, 10, 10));
setBackground(ColorScheme.DARK_GRAY_COLOR);
setLayout(new GridLayout(0, 1, 0, 4));
}
private MaterialTab buildTab(int index)
{
String name = String.valueOf(index + 1);
NoteTab noteTab = new NoteTab(notesManager, index);
MaterialTab materialTab = new MaterialTab(name, tabGroup, noteTab);
materialTab.setPreferredSize(new Dimension(30, 27));
materialTab.setName(name);
final JMenuItem deleteMenuItem = new JMenuItem();
deleteMenuItem.setText(String.format("Delete note %s", name));
deleteMenuItem.addActionListener(e ->
{
if (JOptionPane.showConfirmDialog(ClientUI.getFrame(), String.format("Delete note page %s?", name), "Notes", YES_NO_OPTION) != YES_OPTION)
{
return;
}
try
{
notesManager.deletePage(index);
}
catch (DeleteOnlyPageException err)
{
SwingUtilities.invokeLater(() -> JOptionPane.showMessageDialog(ClientUI.getFrame(),
"Cannot delete the last page",
"Notes", ERROR_MESSAGE));
}
});
final JPopupMenu contextMenu = new JPopupMenu();
contextMenu.setBorder(new EmptyBorder(5, 5, 5, 5));
contextMenu.add(deleteMenuItem);
materialTab.setComponentPopupMenu(contextMenu);
return materialTab;
}
/**
* Builds the players list field (containing the amount of players logged in that world).
*/
private JPanel buildPlayersField()
{
JPanel column = new JPanel(new BorderLayout());
column.setBorder(new EmptyBorder(0, 5, 0, 5));
playerCountField = new JLabel(world.getPlayers() + "");
playerCountField.setFont(FontManager.getRunescapeSmallFont());
column.add(playerCountField, BorderLayout.WEST);
return column;
}
protected Border createNonRolloverBorder() {
if (XPStyle.getXP() != null) {
return new EmptyBorder(3, 3, 3, 3);
} else {
return super.createNonRolloverBorder();
}
}
private void buildPanel() {
setLayout(new PairLayout(10, 10, 160));
setBorder(new EmptyBorder(0, 5, 5, 5));
stackOffset = new JTextField();
refTypes = new GhidraComboBox<>(STACK_REF_TYPES);
add(new GLabel("Stack Offset:", SwingConstants.RIGHT));
add(stackOffset);
add(new GLabel("Ref-Type:", SwingConstants.RIGHT));
add(refTypes);
}
UpdatePanel(SuppliesTrackerPanel suppliesTrackerPanel)
{
this.panel = suppliesTrackerPanel;
setBorder(new EmptyBorder(6, 6, 6, 6));
setBackground(ColorScheme.DARK_GRAY_COLOR);
setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
JEditorPane editorPane = new JEditorPane();
editorPane.setEditable(false);
java.net.URL helpURL = UpdatePanel.class.getResource(
"Info.html");
if (helpURL != null)
{
try
{
editorPane.setPage(helpURL);
}
catch (IOException e)
{
throw new IllegalStateException("File not found");
}
}
JButton close = new JButton("Close info");
close.addActionListener(e ->
{
this.setVisible(false);
panel.updateOverall();
panel.getInfo().setVisible(true);
panel.getLogsContainer().setVisible(true);
});
this.add(close);
this.add(editorPane);
}
public static void main(String[] args) {
JEditorPane ep = new JEditorPane();
ep.setContentType("text/html");
ep.setText("<html><body>abc</body></html>");
ep.setBorder(new EmptyBorder(20, 20, 20, 20));
ep.setBounds(0, 0, 100, 100);
JTextComponent.DropLocation location =
(JTextComponent.DropLocation) SwingAccessor.getJTextComponentAccessor().dropLocationForPoint(ep,
new Point(0, 0));
if (location.getBias() == null) {
throw new RuntimeException("null bias");
}
}
TimeTrackingPanel(ItemManager itemManager, TimeTrackingConfig config,
FarmingTracker farmingTracker, BirdHouseTracker birdHouseTracker, ClockManager clockManager,
FarmingContractManager farmingContractManager)
{
super(false);
this.itemManager = itemManager;
this.config = config;
setLayout(new BorderLayout());
setBackground(ColorScheme.DARK_GRAY_COLOR);
display.setBorder(new EmptyBorder(10, 10, 8, 10));
tabGroup.setLayout(new GridLayout(0, 6, 7, 7));
tabGroup.setBorder(new EmptyBorder(10, 10, 0, 10));
add(tabGroup, BorderLayout.NORTH);
add(display, BorderLayout.CENTER);
addTab(Tab.OVERVIEW, new OverviewTabPanel(itemManager, config, this, farmingTracker, birdHouseTracker, clockManager,
farmingContractManager));
addTab(Tab.CLOCK, clockManager.getClockTabPanel());
addTab(Tab.BIRD_HOUSE, birdHouseTracker.createBirdHouseTabPanel());
for (Tab tab : Tab.FARMING_TABS)
{
addTab(tab, farmingTracker.createTabPanel(tab, farmingContractManager));
}
}
/**
* Check behaviour of method TitledBorder.getTitleColor()
*/
private static void checkTitleColor() {
TitledBorder titledBorder = new TitledBorder(new EmptyBorder(1, 1, 1, 1));
Color defaultColor = UIManager.getLookAndFeelDefaults().getColor("TitledBorder.titleColor");
Color titledBorderColor = titledBorder.getTitleColor();
// check default configuration
if (defaultColor == null) {
if (titledBorderColor == null) {
return;
}
else {
throw new RuntimeException("TitledBorder default color should be null");
}
}
if (!defaultColor.equals(titledBorderColor)) {
throw new RuntimeException("L&F default color " + defaultColor.toString()
+ " differs from TitledBorder color " + titledBorderColor.toString());
}
// title color is explicitly specified
Color color = Color.green;
titledBorder.setTitleColor(color);
if (!color.equals(titledBorder.getTitleColor())) {
throw new RuntimeException("TitledBorder color should be " + color.toString());
}
// title color is unspecified
titledBorder.setTitleColor(null);
if (!defaultColor.equals(titledBorder.getTitleColor())) {
throw new RuntimeException("L&F default color " + defaultColor.toString()
+ " differs from TitledBorder color " + titledBorderColor.toString());
}
}
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;
}
protected TitledBorder getObject() {
return new TitledBorder(
new EmptyBorder(1, 2, 3, 4),
"TITLE",
TitledBorder.CENTER,
TitledBorder.ABOVE_TOP,
new Font("Arial", Font.ITALIC, 12),
Color.RED);
}
ToolDialog(String title, PolicyTool tool, ToolWindow tw, boolean modal) {
super(tw, modal);
setTitle(title);
this.tool = tool;
this.tw = tw;
addWindowListener(new ChildWindowListener(this));
// Create some space around components
((JPanel)getContentPane()).setBorder(new EmptyBorder(6, 6, 6, 6));
}
@Override
protected Component createNextButton() {
nextButton = createArrow(SwingConstants.NORTH);
nextButton.setName("Spinner.nextButton");
nextButton.setBorder(new EmptyBorder(1, 1, 1, 1));
nextButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
installNextButtonListeners(nextButton);
return nextButton;
}
protected void setupTabbedPane() {
label.setBorder(new EmptyBorder(0, 5, 0, 5));
JPanelUIResource buttonHolder = new JPanelUIResource();
buttonHolder.setLayout(new BoxLayout(buttonHolder, BoxLayout.X_AXIS));
buttonHolder.add(Box.createHorizontalStrut(1));
buttonHolder.add(closeButton);
buttonHolder.add(Box.createHorizontalStrut(1));
buttonHolder.setOpaque(false);
tabbedPane.setOpaque(false);
tabbedPane.putClientProperty("JTabbedPane.leadingComponent", label);
tabbedPane.putClientProperty("JTabbedPane.trailingComponent", buttonHolder);
}
protected HeaderButton createCloseButton() {
HeaderButton closeButton = new HeaderButton(UIManager.getIcon("TabFramePopup.close.icon"), this);
closeButton.setBorder(new EmptyBorder(4, 4, 4, 4));
closeButton.addActionListener(e -> popupComponent.close());
String tooltip = ResourceUtil.getResourceBundle("actions", popupComponent).getString("Actions.close");
tooltip = tooltip + " (" + UIManager.getString("TabFramePopup.closeTooltipTextHint") + ")";
closeButton.setToolTipText(tooltip);
return closeButton;
}
private String parsePreview(final String key, final Object val, final int ident) {
Object value = getValue(val);
if (value instanceof Color) {
return StringUtil.repeat(IDENT, ident)
+ String.format("<td style=\"background-color: #%s\" width=\"%d\" height=\"%d\">\n",
ColorUtil.toHex((Color) value), SAMPLE_WIDTH, SAMPLE_HEIGHT);
} else if (value instanceof DarkSVGIcon) {
return parseSVGIcon((DarkSVGIcon) value, ident);
} else if ((value instanceof Border && !(value instanceof EmptyBorder))
|| value instanceof Font
|| (value instanceof Icon && !(value instanceof EmptyIcon))) {
return parseImage(key, value, ident);
}
return StringUtil.repeat(IDENT, ident) + "<td></td>\n";
}