本文整理了Java中javax.swing.JSpinner.setPreferredSize()
方法的一些代码示例,展示了JSpinner.setPreferredSize()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSpinner.setPreferredSize()
方法的具体详情如下:
包路径:javax.swing.JSpinner
类名称:JSpinner
方法名:setPreferredSize
暂无
代码示例来源:origin: runelite/runelite
thicknessSpinner.setPreferredSize(new Dimension(50, 20));
thicknessSpinner.addChangeListener(ce -> updateThickness(true));
代码示例来源:origin: ron190/jsql-injection
this.maximumLength.setToolTipText(I18n.valueByKey("BRUTEFORCE_MAX_TOOLTIP"));
this.minimumLength.setPreferredSize(new Dimension(38, (int) this.minimumLength.getPreferredSize().getHeight()));
this.maximumLength.setPreferredSize(new Dimension(38, (int) this.maximumLength.getPreferredSize().getHeight()));
this.minimumLength.setMaximumSize(new Dimension(38, (int) this.minimumLength.getPreferredSize().getHeight()));
this.maximumLength.setMaximumSize(new Dimension(38, (int) this.maximumLength.getPreferredSize().getHeight()));
代码示例来源:origin: stackoverflow.com
public static JPanel makeTop(String textName){
JTextField textBox = new JTextField(textName);
textBox.setPreferredSize(new Dimension(100,50));
textBox.setHorizontalAlignment(JTextField.CENTER);
textBox.setEditable(false);
SpinnerNumberModel numSpinner = new SpinnerNumberModel(10,0,100,1);
JSpinner spinner = new JSpinner(numSpinner);
spinner.setPreferredSize(new Dimension(100,50));
JPanel panel = new JPanel(new FlowLayout());
panel.add(textBox);
panel.add(spinner);
return panel;
}
代码示例来源:origin: net.sourceforge.ondex.apps/ovtk2
public ConceptNeighbourhood() {
super(new FlowLayout(FlowLayout.LEADING));
this.add(new JLabel("Include neigbours at level:"));
level.setPreferredSize(new Dimension(80, 20));
this.add(level);
}
}
代码示例来源:origin: nz.ac.waikato.cms.weka/meka
/**
* Updates the layout.
*/
protected void update() {
int i;
Dimension preferred;
setLayout(new GridLayout(m_Rows.size(), 1, m_GapHorizontal, m_GapVertical));
for (i = 0; i < m_Rows.size(); i++)
add(m_Rows.get(i));
// set preferred dimensions for JSpinners
for (i = 0; i < m_Rows.size(); i++) {
if (m_Parameters.get(i) instanceof JSpinner)
((JSpinner) m_Parameters.get(i)).setPreferredSize((Dimension) m_PreferredDimensionJSpinner.clone());
}
// determine largest preferred size
preferred = new Dimension(0, 0);
for (i = 0; i < m_Rows.size(); i++) {
if (m_Labels.get(i).getPreferredSize().getWidth() > preferred.getWidth())
preferred = m_Labels.get(i).getPreferredSize();
}
// update preferred sizes
for (i = 0; i < m_Rows.size(); i++)
m_Labels.get(i).setPreferredSize(preferred);
}
代码示例来源:origin: net.sf.meka/meka
/**
* Updates the layout.
*/
protected void update() {
int i;
Dimension preferred;
setLayout(new GridLayout(m_Rows.size(), 1, m_GapHorizontal, m_GapVertical));
for (i = 0; i < m_Rows.size(); i++)
add(m_Rows.get(i));
// set preferred dimensions for JSpinners
for (i = 0; i < m_Rows.size(); i++) {
if (m_Parameters.get(i) instanceof JSpinner)
((JSpinner) m_Parameters.get(i)).setPreferredSize((Dimension) m_PreferredDimensionJSpinner.clone());
}
// determine largest preferred size
preferred = new Dimension(0, 0);
for (i = 0; i < m_Rows.size(); i++) {
if (m_Labels.get(i).getPreferredSize().getWidth() > preferred.getWidth())
preferred = m_Labels.get(i).getPreferredSize();
}
// update preferred sizes
for (i = 0; i < m_Rows.size(); i++)
m_Labels.get(i).setPreferredSize(preferred);
}
代码示例来源:origin: stackoverflow.com
public void hideSpinnerArrow(JSpinner spinner) {
Dimension d = spinner.getPreferredSize();
d.width = 30;
spinner.setUI(new BasicSpinnerUI() {
protected Component createNextButton() {
return null;
}
protected Component createPreviousButton() {
return null;
}
});
spinner.setPreferredSize(d);
}
代码示例来源:origin: nl.cloudfarming.client/task-core
private void init() {
setLayout(new MigLayout("wrap 2, insets 0 0 0 0"));
workWidthSpinner = new javax.swing.JSpinner();
workWidthSpinner.setPreferredSize(new Dimension(72, FormRow.ROW_HEIGHT));
workWidthSpinner.setMinimumSize(new Dimension(72, FormRow.ROW_HEIGHT));
workWidthLabel = new JLabel(NbBundle.getMessage(WorkWidthPanel.class, "WorkWidthPanel.workWidthLabel.text"));
workWidthMeasurementLabel = new JLabel(NbBundle.getMessage(WorkWidthPanel.class, "WorkWidthPanel.workWidthMeasurementLabel.text"));
JPanel spinnerPanel = new JPanel(new MigLayout("wrap 2, insets 0 0 0 0"));
setBackground(java.awt.Color.white);
spinnerPanel.setBackground(java.awt.Color.white);
spinnerPanel.add(workWidthSpinner);
spinnerPanel.add(workWidthMeasurementLabel);
add(new FormRow(false, workWidthLabel, spinnerPanel));
}
代码示例来源:origin: sarahtattersall/PIPE
/**
* Initializes the capacity spinner
* @param placeEditorPanel panel
* @param row of the panel
*/
private void initializeCapacitySpinner(JPanel placeEditorPanel, int row) {
capacitySpinner.setModel(new SpinnerNumberModel(placeController.getCapacity(), 0, Integer.MAX_VALUE, 1));
capacitySpinner.setMinimumSize(new Dimension(50, 20));
capacitySpinner.setPreferredSize(new Dimension(50, 20));
capacitySpinner.addChangeListener(new ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
capacitySpinnerStateChanged(evt);
}
});
GridBagConstraints capacityConstraints = new GridBagConstraints();
capacityConstraints.gridx = 1;
capacityConstraints.gridy = row;
capacityConstraints.fill = GridBagConstraints.HORIZONTAL;
capacityConstraints.insets = new Insets(3, 3, 3, 3);
placeEditorPanel.add(capacitySpinner, capacityConstraints);
}
代码示例来源:origin: cmu-phil/tetrad
/**
* Builds the panel.
*/
public void setup() {
SpinnerNumberModel model = new SpinnerNumberModel(this.params.getInt("numTimeLags", 1),
0, Integer.MAX_VALUE, 1);
JSpinner jSpinner = new JSpinner(model);
jSpinner.setPreferredSize(jSpinner.getPreferredSize());
model.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
SpinnerNumberModel model = (SpinnerNumberModel) e.getSource();
params.set("numTimeLags", model.getNumber().intValue());
}
});
Box b1 = Box.createHorizontalBox();
b1.add(new JLabel("Number of lags: "));
b1.add(Box.createHorizontalGlue());
b1.add(Box.createHorizontalStrut(15));
b1.add(jSpinner);
b1.setBorder(new EmptyBorder(10, 10, 10, 10));
add(b1, BorderLayout.CENTER);
}
代码示例来源:origin: cmu-phil/tetrad
/**
* Builds the panel.
*/
public void setup() {
SpinnerNumberModel model = new SpinnerNumberModel(this.params.getInt("numTimeLags", 1),
0, Integer.MAX_VALUE, 1);
JSpinner jSpinner = new JSpinner(model);
jSpinner.setPreferredSize(jSpinner.getPreferredSize());
model.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
SpinnerNumberModel model = (SpinnerNumberModel) e.getSource();
params.set("numTimeLags", model.getNumber().intValue());
}
});
Box b1 = Box.createHorizontalBox();
b1.add(new JLabel("Number of time lags: "));
b1.add(Box.createHorizontalGlue());
b1.add(Box.createHorizontalStrut(15));
b1.add(jSpinner);
b1.setBorder(new EmptyBorder(10, 10, 10, 10));
add(b1, BorderLayout.CENTER);
}
代码示例来源:origin: io.github.dheid/fontchooser
private void initSizeSpinner() {
int spinnerHeight = (int) sizeSpinner.getPreferredSize().getHeight();
sizeSpinner.setPreferredSize(new Dimension(60, spinnerHeight));
sizeSpinner.setModel(new SpinnerNumberModel(12, 6, 128, 1));
sizeSpinner.addChangeListener(event -> {
Integer value = (Integer) sizeSpinner.getValue();
int index = ((DefaultListModel<Integer>) sizeList.getModel()).indexOf(value);
if (index > -1) {
sizeList.setSelectedValue(value, true);
} else {
sizeList.clearSelection();
}
});
}
代码示例来源:origin: org.boofcv/boofcv-swing
protected JSpinner spinner( double initial , double minimum , double maximum, double stepSize,
String formatString , int digits ) {
JSpinner spinner = new JSpinner(new SpinnerNumberModel(initial, minimum, maximum, stepSize));
JSpinner.NumberEditor editor = new JSpinner.NumberEditor(spinner,formatString);
spinner.setEditor(editor);
editor.getTextField().setHorizontalAlignment(SwingConstants.CENTER);
Dimension d = spinner.getPreferredSize();
d.width = digits*9;
spinner.setPreferredSize(d);
spinner.setMaximumSize(d);
// force it to render using the format specified above. A bit of a hack. Got a better idea?
spinner.setValue(1-initial);spinner.setValue(initial);
spinner.addChangeListener((ChangeListener)this);
return spinner;
}
代码示例来源:origin: org.boofcv/boofcv-swing
protected JSpinner spinner( double initial , double minimum , double maximum, double stepSize,
int integerDigits, int fractionDigits ) {
JSpinner spinner = new JSpinner(new SpinnerNumberModel(initial, minimum, maximum, stepSize));
JSpinner.NumberEditor editor = (JSpinner.NumberEditor)spinner.getEditor();
DecimalFormat format = editor.getFormat();
format.setMinimumFractionDigits(fractionDigits);
format.setMinimumIntegerDigits(integerDigits);
editor.getTextField().setHorizontalAlignment(SwingConstants.CENTER);
Dimension d = spinner.getPreferredSize();
d.width = (integerDigits+1+fractionDigits)*9;
spinner.setPreferredSize(d);
spinner.setMaximumSize(d);
// force it to render using the format specified above. A bit of a hack. Got a better idea?
spinner.setValue(1-initial);spinner.setValue(initial);
spinner.addChangeListener((ChangeListener)this);
return spinner;
}
代码示例来源:origin: org.boofcv/demonstrations
public CannyControlBar( int blurRadius , int threshold ) {
this.blurRadius = blurRadius;
this.threshold = threshold;
setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
controlBlur = new JSpinner(new SpinnerNumberModel(blurRadius,1,20,1));
controlBlur.addChangeListener(this);
controlBlur.setPreferredSize(new Dimension((int)controlBlur.getPreferredSize().getWidth(),(int)controlBlur.getPreferredSize().getHeight()+8));
controlBlur.setMaximumSize(controlBlur.getPreferredSize());
controlThreshold = new JSlider(JSlider.HORIZONTAL,5,100,threshold);
controlThreshold.setMajorTickSpacing(20);
controlThreshold.setPaintTicks(true);
controlThreshold.addChangeListener(this);
add(new JLabel("Blur Radius"));
add(controlBlur);
add(new JLabel("Threshold"));
add(controlThreshold);
add(Box.createHorizontalGlue());
}
代码示例来源:origin: sdedit/sdedit
private void initialize () {
setLayout(new BorderLayout());
Adjustable adjustable = getProperty().getWriteMethod().getAnnotation(Adjustable.class);
min = adjustable.min();
max = adjustable.max();
SpinnerNumberModel model = new SpinnerNumberModel(
adjustable.min(), adjustable.min(), adjustable.max(),
adjustable.step());
spinner = new JSpinner(model);
spinner.setPreferredSize(new Dimension(100,20));
spinner.addChangeListener(this);
label = new JLabel(adjustable.info());
label.setBorder(BorderFactory.createEmptyBorder(0,4,0,0));
add(spinner, BorderLayout.WEST);
add(label, BorderLayout.CENTER);
}
代码示例来源:origin: org.scijava/scijava-ui-swing
/**
* Limit component width to a certain maximum. This is a HACK to work around
* an issue with Double-based spinners that attempt to size themselves very
* large (presumably to match Double.MAX_VALUE).
*/
private void limitWidth(final int maxWidth) {
final Dimension minSize = spinner.getMinimumSize();
if (minSize.width > maxWidth) {
minSize.width = maxWidth;
spinner.setMinimumSize(minSize);
}
final Dimension prefSize = spinner.getPreferredSize();
if (prefSize.width > maxWidth) {
prefSize.width = maxWidth;
spinner.setPreferredSize(prefSize);
}
}
代码示例来源:origin: net.imagej/ij-ui-swing
/**
* Limit component width to a certain maximum. This is a HACK to work around
* an issue with Double-based spinners that attempt to size themselves very
* large (presumably to match Double.MAX_VALUE).
*/
private void limitWidth(final int maxWidth) {
final Dimension minSize = spinner.getMinimumSize();
if (minSize.width > maxWidth) {
minSize.width = maxWidth;
spinner.setMinimumSize(minSize);
}
final Dimension prefSize = spinner.getPreferredSize();
if (prefSize.width > maxWidth) {
prefSize.width = maxWidth;
spinner.setPreferredSize(prefSize);
}
}
代码示例来源:origin: org.boofcv/boofcv-swing
protected void configureSpinnerFloat(JSpinner spinner, int integerDigits, int fractionDigits) {
double min = ((Number)((SpinnerNumberModel)spinner.getModel()).getMinimum()).doubleValue();
int adjust = min < 0 ? 1 : 0;
JSpinner.NumberEditor editor = (JSpinner.NumberEditor)spinner.getEditor();
DecimalFormat format = editor.getFormat();
format.setMinimumFractionDigits(fractionDigits);
format.setMinimumIntegerDigits(integerDigits);
editor.getTextField().setHorizontalAlignment(SwingConstants.CENTER);
Dimension d = spinner.getPreferredSize();
d.width = (adjust+integerDigits+1+fractionDigits)*11;
spinner.setPreferredSize(d);
spinner.setMaximumSize(d);
}
代码示例来源:origin: org.boofcv/demonstrations
private void configureSpinnerFloat( JSpinner spinner ) {
JSpinner.NumberEditor editor = (JSpinner.NumberEditor)spinner.getEditor();
DecimalFormat format = editor.getFormat();
format.setMinimumFractionDigits(3);
format.setMinimumIntegerDigits(1);
editor.getTextField().setHorizontalAlignment(SwingConstants.CENTER);
Dimension d = spinner.getPreferredSize();
d.width = 60;
spinner.setPreferredSize(d);
spinner.addChangeListener(this);
spinner.setMaximumSize(d);
}
内容来源于网络,如有侵权,请联系作者删除!