本文整理了Java中javax.swing.JComboBox.getFont()
方法的一些代码示例,展示了JComboBox.getFont()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JComboBox.getFont()
方法的具体详情如下:
包路径:javax.swing.JComboBox
类名称:JComboBox
方法名:getFont
暂无
代码示例来源:origin: org.ihtsdo/wb-api
public int getWidestItemWidth() {
int numItems = comboBox.getItemCount();
Font font = comboBox.getFont();
FontMetrics metrics = comboBox.getFontMetrics(font);
int widest = 0;
for (int i = 0; i < numItems; i++) {
Object item = comboBox.getItemAt(i);
int lineWidth = metrics.stringWidth(item.toString());
widest = Math.max(widest, lineWidth);
}
return widest;
}
}
代码示例来源:origin: com.github.insubstantial/substance
@Override
protected Dimension getDefaultSize() {
Component rend = new SubstanceDefaultComboBoxRenderer(this.comboBox)
.getListCellRendererComponent(listBox, " ", -1, false, false);
rend.setFont(this.comboBox.getFont());
return rend.getPreferredSize();
}
代码示例来源:origin: com.jtattoo/JTattoo
public Dimension getPreferredSize(JComponent c) {
Dimension size = super.getPreferredSize(c);
if (comboBox.getGraphics() != null) {
FontMetrics fm = JTattooUtilities.getFontMetrics(comboBox, comboBox.getGraphics(), comboBox.getFont());
size.height = fm.getHeight() + 2;
if (UIManager.getLookAndFeel() instanceof AbstractLookAndFeel) {
AbstractLookAndFeel laf = (AbstractLookAndFeel)UIManager.getLookAndFeel();
size.height = Math.max(size.height, laf.getIconFactory().getDownArrowIcon().getIconHeight() + 2);
}
}
return new Dimension(size.width + 2, size.height + 2);
}
代码示例来源:origin: net.java.dev.swing-layout/swing-layout
private int getComboBoxBaseline(JComboBox combobox, int height) {
Insets insets = combobox.getInsets();
int y = insets.top;
height -= (insets.top + insets.bottom);
if (combobox.isEditable()) {
ComboBoxEditor editor = combobox.getEditor();
if (editor != null && (editor.getEditorComponent() instanceof
JTextField)) {
JTextField tf = (JTextField)editor.getEditorComponent();
return y + getSingleLineTextBaseline(tf, height);
}
}
y -= 1;
// Use the renderer to calculate baseline
ListCellRenderer renderer = combobox.getRenderer();
if (renderer instanceof JLabel) {
return y + getLabelBaseline((JLabel)renderer, height);
}
// Renderer isn't a label, use metrics directly.
FontMetrics fm = combobox.getFontMetrics(combobox.getFont());
return y + fm.getAscent();
}
代码示例来源:origin: org.java.net.substance/substance
@Override
protected Dimension getDefaultSize() {
Component rend = new SubstanceDefaultComboBoxRenderer(this.comboBox)
.getListCellRendererComponent(listBox, " ", -1, false, false);
rend.setFont(this.comboBox.getFont());
return rend.getPreferredSize();
}
代码示例来源:origin: cmu-phil/tetrad
public void setup() {
JButton info = new JButton("Help");
info.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
SessionUtils.showPermissibleParentsDialog(getSelectedModel(),
modelClassesBox, false, false);
}
});
JLabel l1 = new JLabel("Node name: " + nodeName);
l1.setForeground(Color.black);
setLayout(new BorderLayout());
Box b1 = Box.createVerticalBox();
Box b2 = Box.createHorizontalBox();
b2.add(l1);
b2.add(Box.createHorizontalGlue());
b1.add(b2);
b1.add(Box.createVerticalStrut(5));
Box b3 = Box.createHorizontalBox();
b3.add(modelClassesBox);
Font font = this.modelClassesBox.getFont();
l1.setFont(font);
b3.add(Box.createGlue());
b3.add(info);
b1.add(b3);
add(b1, BorderLayout.CENTER);
}
代码示例来源:origin: khuxtable/seaglass
currentValuePane.add(comp);
Font f = comboBox.getFont();
代码示例来源:origin: org.java.net.substance/substance
@Override
protected JButton createArrowButton() {
SubstanceDropDownButton result = new SubstanceDropDownButton(
this.comboBox);
result.setFont(this.comboBox.getFont());
result.setIcon(getCurrentIcon(result));
return result;
}
代码示例来源:origin: com.github.insubstantial/substance
@Override
protected JButton createArrowButton() {
SubstanceDropDownButton result = new SubstanceDropDownButton(
this.comboBox);
result.setFont(this.comboBox.getFont());
result.setIcon(getCurrentIcon(result));
return result;
}
代码示例来源:origin: khuxtable/seaglass
/**
* Configures the list which is used to hold the combo box items in the
* popup. This method is called when the UI class is created.
*/
@Override
protected void configureList() {
list.setFont(comboBox.getFont());
list.setBorder(null);
list.setCellRenderer(comboBox.getRenderer());
list.setFocusable(false);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
int selectedIndex = comboBox.getSelectedIndex();
if (selectedIndex == -1) {
list.clearSelection();
} else {
list.setSelectedIndex(selectedIndex);
list.ensureIndexIsVisible(selectedIndex);
}
installListListeners();
}
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/toniclf
/**
* Return the default size of an empty display area of the combo box using
* the current renderer and font.
*
* @return the size of an empty display area
* @see getDisplaySize
*/
protected Dimension getDefaultSize()
{
// Calculates the height and width using the default text renderer
Component c=
getDefaultListCellRenderer().getListCellRendererComponent(
listBox,
" ",
-1,
false,
false);
currentValuePane.add(c);
c.setFont(comboBox.getFont());
Dimension d= c.getPreferredSize();
currentValuePane.remove(c);
return new Dimension(d.width, d.height);
}
代码示例来源:origin: com.github.arnabk/pgslookandfeel
c.setBackground(UIManager.getColor("ComboBox.background"));
c.setFont(comboBox.getFont());
if (comboBox.isEnabled()) {
c.setForeground(comboBox.getForeground());
代码示例来源:origin: com.synaptix/SynaptixTattoo
/**
* Configures the list which is used to hold the combo box items in the
* popup. This method is called when the UI class is created.
*
* @see #createList
*/
protected void configureList() {
list.setFont(comboBox.getFont());
list.setForeground(comboBox.getForeground());
list.setBackground(comboBox.getBackground());
list.setSelectionForeground(UIManager
.getColor("ComboBox.selectionForeground"));
list.setSelectionBackground(UIManager
.getColor("ComboBox.selectionBackground"));
list.setBorder(null);
list.setCellRenderer(comboBox.getRenderer());
list.setFocusable(false);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
setListSelection(comboBox.getSelectedIndex());
installListListeners();
}
代码示例来源:origin: org.gdl-lang.gdl-tools/cds-gui-swing
private static void disable(JComboBox comboBox) {
comboBox.setFocusable(false);
comboBox.setUI(new DisabledComboUI());
comboBox.setFont(comboBox.getFont().deriveFont(Font.PLAIN));
ComboBoxEditor editor = comboBox.getEditor();
if (editor != null && editor.getEditorComponent() instanceof JTextComponent) {
((JTextComponent) editor.getEditorComponent()).setEditable(false);
}
}
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/toniclf
editor.setFont(comboBox.getFont());
代码示例来源:origin: Multibit-Legacy/multibit-hd
/**
* @param listener The action listener to alert when the selection is made
* @param bitcoinConfiguration The Bitcoin configuration to use
*
* @return A new "Bitcoin symbol" combo box (e.g. "mB", "XBT" etc)
*/
public static JComboBox<BitcoinSymbol> newBitcoinSymbolComboBox(ActionListener listener, BitcoinConfiguration bitcoinConfiguration) {
// Order of insertion is important here
JComboBox<BitcoinSymbol> comboBox = newReadOnlyComboBox(BitcoinSymbol.values());
// Ensure it is accessible
AccessibilityDecorator.apply(comboBox, MessageKey.SELECT_BITCOIN_SYMBOL, MessageKey.SELECT_BITCOIN_SYMBOL_TOOLTIP);
// Increase default font size
comboBox.setFont(comboBox.getFont().deriveFont(MultiBitUI.COMBO_BOX_TEXT_FONT_SIZE));
// Ensure we have no ugly scrollbar
comboBox.setMaximumRowCount(BitcoinSymbol.values().length);
// Use a list cell renderer to ensure Bitcoin symbols are correctly presented
ListCellRenderer<BitcoinSymbol> renderer = new BitcoinSymbolListCellRenderer();
comboBox.setRenderer(renderer);
// Ensure we start with the given symbol selected
BitcoinSymbol bitcoinSymbol = BitcoinSymbol.of(bitcoinConfiguration.getBitcoinSymbol());
comboBox.setSelectedIndex(bitcoinSymbol.ordinal());
// Add the listener at the end to avoid false events
comboBox.setActionCommand(BITCOIN_SYMBOL_COMMAND);
comboBox.addActionListener(listener);
return comboBox;
}
代码示例来源:origin: net.sf.squirrel-sql.thirdpary-non-maven/openide
public void paintCurrentValue(Graphics g, Rectangle bounds,boolean hasFocus) {
ListCellRenderer renderer = comboBox.getRenderer();
//Fix for an obscure condition when renderer may be null -
//can't figure how this can happen unless the combo box is
//painted before installUI() has completed (which is called
//by the superclass constructor calling updateUI(). Only
//happens when opening an individual Properties window. Maybe
//the window is constructed off the AWT thread?
if ((listBox == null) || (renderer == null)) {
return;
}
Component c;
c = renderer.getListCellRendererComponent( listBox,
comboBox.getSelectedItem(),
-1,
false,
false );
c.setFont(comboBox.getFont());
c.setForeground(comboBox.isEnabled() ? comboBox.getForeground() :
PropUtils.getDisabledForeground());
c.setBackground(comboBox.getBackground());
boolean shouldValidate = false;
if (c instanceof JPanel) {
shouldValidate = true;
}
currentValuePane.paintComponent(g,c,comboBox,bounds.x,bounds.y,
bounds.width,bounds.height, shouldValidate);
}
代码示例来源:origin: org.netbeans.api/org-openide-explorer
@Override
public void paintCurrentValue(Graphics g, Rectangle bounds, boolean hasFocus) {
ListCellRenderer renderer = comboBox.getRenderer();
//Fix for an obscure condition when renderer may be null -
//can't figure how this can happen unless the combo box is
//painted before installUI() has completed (which is called
//by the superclass constructor calling updateUI(). Only
//happens when opening an individual Properties window. Maybe
//the window is constructed off the AWT thread?
if ((listBox == null) || (renderer == null)) {
return;
}
Component c;
c = renderer.getListCellRendererComponent(listBox, comboBox.getSelectedItem(), -1, false, false);
c.setFont(comboBox.getFont());
c.setForeground(comboBox.isEnabled() ? comboBox.getForeground() : PropUtils.getDisabledForeground());
c.setBackground(comboBox.getBackground());
boolean shouldValidate = false;
if (c instanceof JPanel) {
shouldValidate = true;
}
currentValuePane.paintComponent(
g, c, comboBox, bounds.x, bounds.y, bounds.width, bounds.height, shouldValidate
);
}
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/openide
public void paintCurrentValue(Graphics g, Rectangle bounds,boolean hasFocus) {
ListCellRenderer renderer = comboBox.getRenderer();
//Fix for an obscure condition when renderer may be null -
//can't figure how this can happen unless the combo box is
//painted before installUI() has completed (which is called
//by the superclass constructor calling updateUI(). Only
//happens when opening an individual Properties window. Maybe
//the window is constructed off the AWT thread?
if ((listBox == null) || (renderer == null)) {
return;
}
Component c;
c = renderer.getListCellRendererComponent( listBox,
comboBox.getSelectedItem(),
-1,
false,
false );
c.setFont(comboBox.getFont());
c.setForeground(comboBox.isEnabled() ? comboBox.getForeground() :
PropUtils.getDisabledForeground());
c.setBackground(comboBox.getBackground());
boolean shouldValidate = false;
if (c instanceof JPanel) {
shouldValidate = true;
}
currentValuePane.paintComponent(g,c,comboBox,bounds.x,bounds.y,
bounds.width,bounds.height, shouldValidate);
}
代码示例来源:origin: bcdev/beam
@Override
protected void initUI() {
setDefaultLabelComponent(true);
_comboBox = new JComboBox();
nameEditorComponent(_comboBox);
// Configure combo box
if (getParameter().getProperties().getDescription() != null) {
_comboBox.setToolTipText(getParameter().getProperties().getDescription());
}
if (getParameter().getProperties().getValueSet() != null) {
_comboBox.setModel(new DefaultComboBoxModel(getParameter().getProperties().getValueSet()));
}
_comboBox.setEnabled(!getParameter().getProperties().isReadOnly());
_comboBox.setEditable(!getParameter().getProperties().isValueSetBound());
JTextComponent textComp = getTextComponent();
if (textComp != null) {
textComp.setInputVerifier(getDefaultInputVerifier());
}
_comboBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
updateParameter();
}
});
java.awt.Font font = _comboBox.getFont();
if (font != null) {
_comboBox.setFont(new java.awt.Font(font.getName(),
Font.PLAIN,
font.getSize()));
}
}
内容来源于网络,如有侵权,请联系作者删除!