http://postimg.org/image/89g61o7jl/42b4a9b9/
在这里,您可以看到具有15的单元格在单元格的高度上添加的像素很少。现在我的问题是如何减小单元格的高度以匹配像http://s13.postimg.org/4qey77daf/how_i_would_like_it.png这样的字体,它包裹单元格的高度以匹配组件的高度。
我问这是因为字体大小正在成为我正在尝试的布局的问题,我想知道如何增加单元格的高度并减少它以便我可以控制组件之间的空间
这是我的源代码:
package migtest;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import net.miginfocom.swing.MigLayout;
public class somexamp extends JFrame{
public somexamp() {
try {
JPanel somepanel = new JPanel(new MigLayout("debug,nogrid,flowy","",""));
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
BufferedImage img = ImageIO.read(new File("src/migtest/misty cloud or windy for land.png"));
ImageIcon icon = new ImageIcon(img);
JLabel label = new JLabel(icon);
JLabel label2 = new JLabel("now");
JLabel label3 = new JLabel("°C");
JLabel label4 = new JLabel("15");
Font tempf = new Font("Verdana", Font.PLAIN, 40);
label4.setFont(tempf);
JCheckBox somenexthing = new JCheckBox("Program argument");
JButton jj = new JButton("Blah");
JButton jm = new JButton("Blah2");
somenexthing.setFont(new Font("Arial", 1, 10));
jj.setPreferredSize(new Dimension(50, 100));
somepanel.add(label2,"");
somepanel.add(label4,"");
somepanel.add(label);
this.setContentPane(somepanel);
this.setSize(600, 400);
this.setVisible(true);
} catch (IOException ex) {
Logger.getLogger(somexamp.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static void main(String[] args) {
new somexamp();
}
}