为什么java中使用BoxLayout时Button设置好的大小会失效,怎么破?
BoxLayoutbox=newBoxLayout(panel3,BoxLayout.Y_AXIS);Dimensiondem2=newDimension(75,50);...
BoxLayout box = new BoxLayout(panel3,BoxLayout.Y_AXIS);
Dimension dem2 = new Dimension(75,50);
button[10].setPreferredSize(dem2);
button[11].setPreferredSize(dem2);
button[12].setPreferredSize(dem2);
button[13].setPreferredSize(dem2);
panel3.setLayout(box);
panel3.add(button[10]);
panel3.add(button[11]);
panel3.add(button[12]);
panel3.add(button[13]); 展开
Dimension dem2 = new Dimension(75,50);
button[10].setPreferredSize(dem2);
button[11].setPreferredSize(dem2);
button[12].setPreferredSize(dem2);
button[13].setPreferredSize(dem2);
panel3.setLayout(box);
panel3.add(button[10]);
panel3.add(button[11]);
panel3.add(button[12]);
panel3.add(button[13]); 展开
1个回答
2015-04-25
展开全部
package image;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
public class Ex
{
public static void main ( String args[] )
{
JFrame frame = new JFrame ("BUTTON");
JButton button = new JButton ("clieck me");
frame.setLayout (null);
button.setBounds (( 800 - 100 ) / 2, ( 600 - 20 ) / 2, 100, 20);
frame.setSize (800, 600);
frame.setLocation (300, 200);
frame.add (button);
frame.setLocationRelativeTo (null);
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
frame.setVisible (true);
}
}
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
public class Ex
{
public static void main ( String args[] )
{
JFrame frame = new JFrame ("BUTTON");
JButton button = new JButton ("clieck me");
frame.setLayout (null);
button.setBounds (( 800 - 100 ) / 2, ( 600 - 20 ) / 2, 100, 20);
frame.setSize (800, 600);
frame.setLocation (300, 200);
frame.add (button);
frame.setLocationRelativeTo (null);
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
frame.setVisible (true);
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询