请问什么是Java可调整大小的布局管理器?
我想调整JFrame布局管理器的大小(实际上是边框布局) 所以我用了setPreferredSize但什么都没发生?有些人告诉我使用另一个布局管理器,那么我应该使用什么布局管理器来扩展我的一个面板的大小呢? 非常感谢。 我的代码:请问什么是Java可调整大小的布局管理器?,java,layout,jframe,layout-manager,Java,Layout,Jframe,Layout Manager,我想调整JFrame布局管理器的大小(实际上是边框布局) 所以我用了setPreferredSize但什么都没发生?有些人告诉我使用另一个布局管理器,那么我应该使用什么布局管理器来扩展我的一个面板的大小呢? 非常感谢。 我的代码: import java.awt.Container; import java.awt.Dimension; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JButton
import java.awt.Container;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.SwingUtilities;
import javax.swing.BoxLayout;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.Graphics;
public class OptimiserMonWifi extends JFrame implements MouseListener {
private JPanel panel;
private JPanel panel2;
private JButton bouton1;
private JButton bouton2;
private JButton bouton3;
private JButton bouton4;
private JCheckBox check1;
private JCheckBox check2;
public OptimiserMonWifi()
{
super("Optimiser Mon Wifi");
//this.setLayout(new CardLayout());
this.setLayout(new BorderLayout());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
this.bouton1 = new JButton("Afficher");
this.bouton2 = new JButton("Réinitialiser");
this.bouton3 = new JButton("Précédent");
this.bouton4 = new JButton("Suivant");
this.check1 = new JCheckBox("Emission");
this.check2 = new JCheckBox("Coordonnées");
this.panel = new JPanel();
//panel.setLayout(new GridLayout(4,2));
panel.setLayout(new BoxLayout(panel, BoxLayout.LINE_AXIS));
panel.setBackground(Color.blue);
this.panel2 = new JPanel();
panel2.setBackground(Color.red);
setPreferredSize(new Dimension(1000,500));
panel2.setPreferredSize(new Dimension(1000,500));
panel2.addMouseListener(this);
this.panel.add(bouton1);
this.panel.add(bouton2);
this.check1.addActionListener(new StateListener());
this.check2.addActionListener(new StateListener());
this.panel.add(check1);
this.panel.add(check2);
this.panel.add(bouton3);
this.panel.add(bouton4);
/*this.getContentPane().add(panel, BorderLayout.NORTH);
this.getContentPane().add(panel2, BorderLayout.CENTER);*/
/*this.getContentPane().add(panel, BUTTONPANNEL);
this.getContentPane().add(panel2, TEXTPANNEL);*/
this.pack();
this.setVisible(true);
}
public void mouseClicked(MouseEvent e) {
int x=e.getX();
int y=e.getY();
System.out.println("x : "+x+" ; y : "+y);//these co-ords are relative to the component
}
//Méthode appelée lors du survol de la souris
public void mouseEntered(MouseEvent event) { }
//Méthode appelée lorsque la souris sort de la zone du bouton
public void mouseExited(MouseEvent event) { }
//Méthode appelée lorsque l'on presse le bouton gauche de la souris
public void mousePressed(MouseEvent event) { }
//Méthode appelée lorsque l'on relâche le clic de souris
public void mouseReleased(MouseEvent event) { }
class StateListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
System.out.println("source : " + ((JCheckBox)e.getSource()).getText() + " - état : " + ((JCheckBox)e.getSource()).isSelected());
}
}
public static void main(String[] args)
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
new OptimiserMonWifi();
}
});
}
}
不调整布局管理器的大小;可以调整JFrame或其子对象(ren)的大小。你想“扩大我的一个面板的尺寸”是什么意思?您希望在什么时候执行此操作—在使JFrame可见之后,还是最初?如果不向我们展示您尝试过的一些代码,我们只能胡乱猜测。我的意思是“扩展我的一个窗格的大小”,但我会编辑我的问题以发布我的代码,这样您就可以看到:我想扩展我的窗格2的高度,因为它实际上非常薄,我希望它的高度更高如果您希望面板比父容器大,那么您需要使用
JScrollPane
我不希望面板比父容器大为什么?这真的是我的代码想要做的吗???(如果是,我不知道?)好的,您是否尝试过使用GridBagLayout
?它将尊重您的组件的首选大小不,我没有,但我读过关于它和许多其他布局,不知道哪一个尝试我现在尝试!哦,不,行得通,行得通,我只是忘记了“这个”前面的“setPreferredSize(新尺寸(1000500));“谢谢你!我会寻找这个布局只是为了获取知识