私はJComboBox
の次元を調べていました(私は他のSwingオブジェクトで提示されているかどうかわかりません)。スイング(JComboBox)バグ?印刷寸法
寸法が印刷されるときに問題が発生します。 バグですか?
ここに私のコード:
JPanel jpPanelOut = new JPanel();
jpPanelOut.setBackground(new java.awt.Color(255, 255, 255));
jpPanelOut.setLayout(new BoxLayout(jpPanelOut, BoxLayout.PAGE_AXIS));
JPanel jpPanel = new JPanel();
jpPanel.setPreferredSize(new Dimension(800, 26));
Font inFont = new Font("Serif", Font.PLAIN, 10);
JPanel jpPanel0 = new JPanel();
jpPanel0.setLayout(new BoxLayout(jpPanel0, BoxLayout.LINE_AXIS));
JLabel jlLabel0 = new JLabel("this is a new text");
jlLabel0.setBorder(javax.swing.BorderFactory.createEtchedBorder());
jlLabel0.setFont(inFont);
JSlider jslSlider0 = new JSlider(JSlider.HORIZONTAL, 0, 1000000000, 1);
jslSlider0.setFont(inFont);
JSpinner jspSpinner0 = new JSpinner(new SpinnerNumberModel(1, 0, 1000000000, 1));
jspSpinner0.setFont(inFont);
JTextField jtfTextField0 = new JTextField("1234567890abcdef_gpqyTÑ",48);
jtfTextField0.setFont(inFont);
JComboBox jcbComboBox0 = new JComboBox<>(new String[] {"Average"});
jcbComboBox0.setFont(inFont);
((JLabel)jcbComboBox0.getRenderer()).setHorizontalAlignment(JLabel.RIGHT);
jpPanel0.add(jlLabel0);
jpPanel0.add(jslSlider0);
jpPanel0.add(jspSpinner0);
jpPanel0.add(jtfTextField0);
jpPanel0.add(jcbComboBox0);
inFont = new Font("Serif", Font.PLAIN, 10);
JPanel jpPanel1 = new JPanel();
jpPanel1.setLayout(new BoxLayout(jpPanel1, BoxLayout.LINE_AXIS));
JLabel jlLabel1 = new JLabel("this is a new text");
jlLabel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
jlLabel1.setFont(inFont);
JSlider jslSlider1 = new JSlider(JSlider.HORIZONTAL, 0, 1000000000, 1);
jslSlider1.setFont(inFont);
JSpinner jspSpinner1 = new JSpinner(new SpinnerNumberModel(1, 0, 1000000000, 1));
jspSpinner1.setFont(inFont);
JTextField jtfTextField1 = new JTextField("1234567890abcdef_gpqyTÑ",48);
jtfTextField1.setFont(inFont);
JComboBox jcbComboBox1 = new JComboBox<>(new String[] {"Average"});
jcbComboBox1.setFont(inFont);
((JLabel)jcbComboBox1.getRenderer()).setHorizontalAlignment(JLabel.RIGHT);
jpPanel1.add(jlLabel1);
jpPanel1.add(jslSlider1);
jpPanel1.add(jspSpinner1);
jpPanel1.add(jtfTextField1);
jpPanel1.add(jcbComboBox1);
System.out.println("Height:"
+ " jtfTextField:" + jtfTextField1.getPreferredSize().getHeight() + ","
+ jtfTextField1.getMinimumSize().getHeight()
+ " jlLabel:" + jlLabel1.getPreferredSize().getHeight() + ","
+ jlLabel1.getMinimumSize().getHeight()
+ " jcbComboBox:" + jcbComboBox1.getPreferredSize().getHeight() + ","
+ jcbComboBox1.getMinimumSize().getHeight()
+ " jslSlider:" + jslSlider1.getPreferredSize().getHeight() + ","
+ jslSlider1.getMinimumSize().getHeight()
+ " jspSpinner:" + jspSpinner1.getPreferredSize().getHeight() + ","
+ jspSpinner1.getMinimumSize().getHeight()
);
jpPanelOut.add(jpPanel);
jpPanelOut.add(jpPanel0);
jpPanelOut.add(jpPanel1);
しかし、寸法が変更されます!
見てください:のJTextFieldの
appereance(幅)
完全なコード
グリーンラインJComboBoxsの赤丸appereance(テキスト)
package myPackage;
import javax.swing.*;
import java.awt.*;
public class NewJFrame extends javax.swing.JFrame {
public NewJFrame() {
initComponents();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jButton1 = new javax.swing.JButton();
jPanel1 = new javax.swing.JPanel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jButton1.setText("jButton1");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 0, Short.MAX_VALUE)
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 220, Short.MAX_VALUE)
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(739, Short.MAX_VALUE)
.addComponent(jButton1)
.addContainerGap())
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 51, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
JPanel jpPanelOut = new JPanel();
jpPanelOut.setBackground(new Color(255, 255, 255));
jpPanelOut.setLayout(new BoxLayout(jpPanelOut, BoxLayout.PAGE_AXIS));
JPanel jpPanel = new JPanel();
jpPanel.setPreferredSize(new Dimension(600, 26));
Font inFont = new Font("Serif", Font.PLAIN, 10);
JPanel jpPanel0 = new JPanel();
jpPanel0.setLayout(new BoxLayout(jpPanel0, BoxLayout.LINE_AXIS));
JLabel jlLabel0 = new JLabel("this is a new text");
jlLabel0.setBorder(BorderFactory.createEtchedBorder());
jlLabel0.setFont(inFont);
JSlider jslSlider0 = new JSlider(JSlider.HORIZONTAL, 0, 1000000000, 1);
jslSlider0.setFont(inFont);
JSpinner jspSpinner0 = new JSpinner(new SpinnerNumberModel(1, 0, 1000000000, 1));
jspSpinner0.setFont(inFont);
JTextField jtfTextField0 = new JTextField("1234567890abcdef_gpqyTÑ",48);
jtfTextField0.setFont(inFont);
JComboBox jcbComboBox0 = new JComboBox<>(new String[] {"Average"});
jcbComboBox0.setFont(inFont);
((JLabel)jcbComboBox0.getRenderer()).setHorizontalAlignment(JLabel.RIGHT);
jpPanel0.add(jlLabel0);
jpPanel0.add(jslSlider0);
jpPanel0.add(jspSpinner0);
jpPanel0.add(jtfTextField0);
jpPanel0.add(jcbComboBox0);
inFont = new Font("Serif", Font.PLAIN, 10);
JPanel jpPanel1 = new JPanel();
jpPanel1.setLayout(new BoxLayout(jpPanel1, BoxLayout.LINE_AXIS));
JLabel jlLabel1 = new JLabel("this is a new text");
jlLabel1.setBorder(BorderFactory.createEtchedBorder());
jlLabel1.setFont(inFont);
JSlider jslSlider1 = new JSlider(JSlider.HORIZONTAL, 0, 1000000000, 1);
jslSlider1.setFont(inFont);
JSpinner jspSpinner1 = new JSpinner(new SpinnerNumberModel(1, 0, 1000000000, 1));
jspSpinner1.setFont(inFont);
JTextField jtfTextField1 = new JTextField("1234567890abcdef_gpqyTÑ",48);
jtfTextField1.setFont(inFont);
JComboBox jcbComboBox1 = new JComboBox<>(new String[] {"Average"});
jcbComboBox1.setFont(inFont);
((JLabel)jcbComboBox1.getRenderer()).setHorizontalAlignment(JLabel.RIGHT);
jpPanel1.add(jlLabel1);
jpPanel1.add(jslSlider1);
jpPanel1.add(jspSpinner1);
jpPanel1.add(jtfTextField1);
jpPanel1.add(jcbComboBox1);
System.out.println("Height:"
+ " jtfTextField:" + jtfTextField1.getPreferredSize().getHeight() + ","
+ jtfTextField1.getMinimumSize().getHeight()
+ " jlLabel:" + jlLabel1.getPreferredSize().getHeight() + ","
+ jlLabel1.getMinimumSize().getHeight()
+ " jcbComboBox:" + jcbComboBox1.getPreferredSize().getHeight() + ","
+ jcbComboBox1.getMinimumSize().getHeight()
+ " jslSlider:" + jslSlider1.getPreferredSize().getHeight() + ","
+ jslSlider1.getMinimumSize().getHeight()
+ " jspSpinner:" + jspSpinner1.getPreferredSize().getHeight() + ","
+ jspSpinner1.getMinimumSize().getHeight()
);
jpPanelOut.add(jpPanel);
jpPanelOut.add(jpPanel0);
jpPanelOut.add(jpPanel1);
jPanel1.removeAll();
jPanel1.setLayout(new GridLayout(1, 1));
jPanel1.add(jpPanelOut);
}
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JPanel jPanel1;
// End of variables declaration
}
ポスト問題を示し、適切な[SSCCE](http://sscce.org/)。コードが提供されている – camickr
に問題が再現できます。実際にこのコードでは、2つの下側パネルが供給された画像に表示されています。問題を再現するためにコードは必要ありません。 –
投稿したコードをコンパイルしてテストできないため、問題を再現できません。 – camickr