本文整理汇总了Java中javax.swing.DefaultListCellRenderer.setHorizontalAlignment方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultListCellRenderer.setHorizontalAlignment方法的具体用法?Java DefaultListCellRenderer.setHorizontalAlignment怎么用?Java DefaultListCellRenderer.setHorizontalAlignment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.DefaultListCellRenderer
的用法示例。
在下文中一共展示了DefaultListCellRenderer.setHorizontalAlignment方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Main
import javax.swing.DefaultListCellRenderer; //导入方法依赖的package包/类
/**
* @main
*/
public Main() {
initComponents();
setLocationRelativeTo(this);
this.setTitle("EVIL INSULT GENERATOR");
this.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/com/imgs/app-icon.png")));
addCombobox();
AutoCompleteDecorator.decorate(this.cmbLanguage);
DefaultListCellRenderer dlcr = new DefaultListCellRenderer();
dlcr.setHorizontalAlignment(DefaultListCellRenderer.CENTER);
cmbLanguage.setRenderer(dlcr);
StyledDocument doc = txtPaneShow.getStyledDocument();
SimpleAttributeSet center = new SimpleAttributeSet();
StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);
doc.setParagraphAttributes(0, doc.getLength(), center, false);
try {
Document doc1 = Jsoup.connect("http://evilinsult.com/generate_insult.php?lang=en").get();
Elements links = doc1.select("body");
for (Element link : links) {
txtPaneShow.setText("\n" + link.text());
}
} catch (RuntimeException e) {
throw e;
} catch (Exception ex) {
txtPaneShow.setText("Insult Outage! Please Check Your Internet Connection And Try Again In Three Minutes");
}
}
示例2: SelectedDatabaseViewer
import javax.swing.DefaultListCellRenderer; //导入方法依赖的package包/类
public SelectedDatabaseViewer() {
dbComboBox = new JComboBox<Database>();
alterButton = new JButton("ALTER");
removeButton = new JButton("DROP");
setLayout(new GridLayout(NROWS, NCOLS, VGAP, HGAP));
setBorder(new EmptyBorder(TOP_PADDING,
LEFT_PADDING,
BOTTOM_PADDING,
RIGHT_PADDING));
// ComboBox settings
dbComboBox.setPreferredSize(new Dimension(COMBOBOX_WIDTH, COMBOBOX_HEIGHT));
DefaultListCellRenderer dlcr = new DefaultListCellRenderer();
dlcr.setHorizontalAlignment(DefaultListCellRenderer.CENTER);
dbComboBox.setRenderer(dlcr);
dbComboBox.setFocusable(false);
JPanel comboBoxContainer = new JPanel();
comboBoxContainer.add(dbComboBox);
JPanel buttonsPanel = new JPanel();
buttonsPanel.add(alterButton);
buttonsPanel.add(removeButton);
add(comboBoxContainer);
add(buttonsPanel);
setMinimumSize(new Dimension(MINIMUM_WIDTH, MINIMUM_HEIGHT));
setMaximumSize(new Dimension(MAXIMUM_WIDTH, MAXIMUM_HEIGHT));
}
示例3: initSizeList
import javax.swing.DefaultListCellRenderer; //导入方法依赖的package包/类
private void initSizeList() {
sizeList.setModel(sizeListModel);
sizeList.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
sizeList.addListSelectionListener(event -> {
if (!event.getValueIsAdjusting()) {
int index = ((DefaultListModel<Integer>) sizeList.getModel()).indexOf(sizeList.getSelectedValue());
if (index > -1) {
sizeSpinner.setValue(sizeList.getSelectedValue());
}
}
});
DefaultListCellRenderer renderer = (DefaultListCellRenderer) sizeList.getCellRenderer();
renderer.setHorizontalAlignment(SwingConstants.RIGHT);
}
示例4: createPlayerRaceSelection
import javax.swing.DefaultListCellRenderer; //导入方法依赖的package包/类
/**
* Create Player config for one player
* @param base The panel
* @param index The player index
* @param listener The action listener
* @return InvisiblePanel with configuration components
*/
private InvisiblePanel createPlayerRaceSelection(final InvisiblePanel base,
final int index, final ActionListener listener) {
InvisiblePanel xinvis = new InvisiblePanel(base);
xinvis.setLayout(new BoxLayout(xinvis, BoxLayout.X_AXIS));
xinvis.add(Box.createRigidArea(new Dimension(25, 25)));
InfoPanel info = new InfoPanel();
info.setLayout(new BoxLayout(info, BoxLayout.Y_AXIS));
if (index == 0) {
info.setTitle("Player " + (index + 1));
} else {
info.setTitle("Player " + (index + 1) + " (AI)");
}
raceImgs[index] = new RaceImagePanel();
raceImgs[index].setRaceToShow(config.getRace(index).getNameSingle());
info.add(raceImgs[index]);
info.add(Box.createRigidArea(new Dimension(5, 5)));
comboRaceSelect[index] = new SpaceComboBox<>(RACE_SELECTION);
comboRaceSelect[index]
.setBackground(GuiStatics.COLOR_DEEP_SPACE_PURPLE_DARK);
comboRaceSelect[index].setForeground(GuiStatics.COLOR_COOL_SPACE_BLUE);
comboRaceSelect[index].setBorder(new SimpleBorder());
comboRaceSelect[index].setFont(GuiStatics.getFontCubellan());
comboRaceSelect[index].getModel()
.setSelectedItem(config.getRace(index).getNameSingle());
DefaultListCellRenderer dlcr = new DefaultListCellRenderer();
dlcr.setHorizontalAlignment(DefaultListCellRenderer.CENTER);
comboRaceSelect[index].setRenderer(dlcr);
comboRaceSelect[index].addActionListener(listener);
comboRaceSelect[index]
.setActionCommand(GameCommands.COMMAND_GALAXY_SETUP + index);
if (config.getMaxPlayers() < (index + 1)) {
comboRaceSelect[index].setEnabled(false);
}
comboRaceSelect[index].setToolTipText(config.getRace(index)
.getFullDescription(false, false));
info.add(comboRaceSelect[index]);
info.add(Box.createRigidArea(new Dimension(5, 5)));
playerName[index] = new JTextField(
"Empire of " + config.getRace(index).getName());
playerName[index].setBackground(GuiStatics.COLOR_DEEP_SPACE_PURPLE_DARK);
playerName[index].setForeground(GuiStatics.COLOR_COOL_SPACE_BLUE);
playerName[index].setFont(GuiStatics.getFontCubellanSmaller());
if (config.getMaxPlayers() < (index + 1)) {
playerName[index].setEnabled(false);
raceImgs[index].setRaceToShow(null);
} else {
playerName[index].setText(config.getPlayerName(index));
comboRaceSelect[index].setToolTipText(config.getRace(index)
.getFullDescription(false, false));
}
info.add(playerName[index]);
info.add(Box.createRigidArea(new Dimension(5, 5)));
xinvis.add(info);
xinvis.add(Box.createRigidArea(new Dimension(25, 25)));
return xinvis;
}
示例5: createGUI
import javax.swing.DefaultListCellRenderer; //导入方法依赖的package包/类
private void createGUI() {
JLabel categoryTitle = new JLabel("Category:");
categoryTitle.setLabelFor(dataTypeSelector);
categoryTitle.setToolTipText("What kind of entry is this?");
DefaultListCellRenderer dlcr = new DefaultListCellRenderer();
dlcr.setHorizontalAlignment(DefaultListCellRenderer.CENTER);
dataTypeSelector = new JComboBox<String>(possibleEntries);
dataTypeSelector.setSelectedIndex(0);
dataTypeSelector.setRenderer(dlcr);
JLabel dataTitle = new JLabel("Title:");
title = new JTextField();
title.setToolTipText("Entry title");
JLabel dataDescription = new JLabel("Description:");
description = new JTextField();
JLabel dataDate = new JLabel("Date (YYYY-MM-DD)");
date = new JFormattedTextField(createFormatter("####-##-##"));
date.setToolTipText("Format: YYYY-MM-DD");
JLabel dataKeywords = new JLabel("Keywords:");
keywords = new JTextField();
keywords.setToolTipText("Keywords and tags that help identify this entry.");
addButton = new JButton("Add Entry");
addButton.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
// for debugging TODO remove this
Data d = new Data(title.getText(), description.getText(), date.getText(), keywords.getText(), possibleEntries[dataTypeSelector.getSelectedIndex()]);
manager.createEntry(d);
if(EnableDebug)
System.out.println("in NewEntryFrame.addButton - adding: " + d.toString());
mwReference.requestListDisplayUpdate();
clearAllTextfields();
hideFrame();
}
});
selectorPane.add(categoryTitle);
selectorPane.add(dataTypeSelector);
selectorPane.add(Box.createVerticalGlue());
selectorPane.add(dataTitle);
selectorPane.add(Box.createHorizontalStrut(10));
selectorPane.add(title);
selectorPane.add(Box.createVerticalGlue());
selectorPane.add(dataDescription);
selectorPane.add(Box.createHorizontalStrut(10));
selectorPane.add(description);
selectorPane.add(Box.createVerticalGlue());
selectorPane.add(dataDate);
selectorPane.add(Box.createHorizontalStrut(10));
selectorPane.add(date);
selectorPane.add(Box.createVerticalGlue());
selectorPane.add(dataKeywords);
selectorPane.add(Box.createHorizontalStrut(10));
selectorPane.add(keywords);
selectorPane.add(Box.createVerticalGlue());
selectorPane.add(addButton);
}