boxlayout

How to make BoxLayout behave as vertical FlowLayout?

只谈情不闲聊 提交于 2019-12-07 13:04:29
问题 FlowLayout performs "pressure" from the right, so as all components are trying to take their minimal widths. Contrary, BoxLayout tries to spread all components to fill entire height of the space. Can I add some filler as last component or something to make all components have minimal heights in BoxLayout ? 回答1: You could use Box.createGlue(), which returns a component that takes up as much space as the BoxLayout will give it. Adding it to the bottom of a vertical BoxLayout will scrunch the

Swing BoxLayout problem with JComboBox without using setXXXSize

拟墨画扇 提交于 2019-12-07 05:35:46
问题 here's an SSCCE: import java.awt.Color; import java.awt.Dimension; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JPanel; public class BoxLayoutTest extends JFrame { public BoxLayoutTest(){ JPanel main = new JPanel(); main.setLayout(new BoxLayout(main, BoxLayout.Y_AXIS)); main.setBackground(Color.red); this.add(main); JPanel northPanel = new JPanel(); JPanel middle = new JPanel();

setMinimumSize() not working for JButton

六眼飞鱼酱① 提交于 2019-12-06 16:41:21
The following code describes a button that is instantiated in a JPanel with a BoxLayout in Page Axis: private class AddInputSetButton extends JButton { public AddInputSetButton() { super("+"); setMinimumSize(new Dimension(100, 100)); pack(); addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { addInputGroup(); } }); } } I have tried setSize(), setPreferredSize(), and setMinimumSize() to no avail, none of them resize the button. I am still relatively new to Java GUIs, so hopefully it is something simple. How do I adjust the size of the button? EDIT:

How to make BoxLayout behave as vertical FlowLayout?

柔情痞子 提交于 2019-12-06 02:39:57
FlowLayout performs "pressure" from the right, so as all components are trying to take their minimal widths. Contrary, BoxLayout tries to spread all components to fill entire height of the space. Can I add some filler as last component or something to make all components have minimal heights in BoxLayout ? You could use Box.createGlue(), which returns a component that takes up as much space as the BoxLayout will give it. Adding it to the bottom of a vertical BoxLayout will scrunch the other components to the top. You could also use nested layouts. 来源: https://stackoverflow.com/questions

how to set component size inside container with BoxLayout

吃可爱长大的小学妹 提交于 2019-12-05 22:43:11
问题 Faced with the problem of using BoxLayout In my example, I try to decrease the height of the text field and change the width of the buttons (as shown in green marker in the picture). I know about the techniques setPrefferedSize () and setMaximumSize (), but it did not work as it should. The line add(Box.createHorizontalGlue ()) also did not help. Thanks for any idea public class Testy extends JPanel { public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() {

Swing BoxLayout problem with JComboBox without using setXXXSize

无人久伴 提交于 2019-12-05 10:48:07
here's an SSCCE: import java.awt.Color; import java.awt.Dimension; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JPanel; public class BoxLayoutTest extends JFrame { public BoxLayoutTest(){ JPanel main = new JPanel(); main.setLayout(new BoxLayout(main, BoxLayout.Y_AXIS)); main.setBackground(Color.red); this.add(main); JPanel northPanel = new JPanel(); JPanel middle = new JPanel(); middle.setLayout(new BoxLayout(middle, BoxLayout.X_AXIS)); middle.add(new JButton("FOO")); middle.add(Box

Creating a space for Graphics2D drawings

百般思念 提交于 2019-12-02 13:11:47
I want to draw a simple board made of Graphics2D rectangles but I also want to have one JButton under this board. I know the exact dimensions of this board in pixels and I was trying to deal with getContentPane() method and BoxLayout, like this: frame.getContentPane().add(board); frame.getContentPane().add(Box.createRigidArea(new Dimension(bWidth, bHeight))); frame.getContentPane().add(new JButton("Start")); frame.pack(); But RigidArea isn't truly invisible and it overrides my drawings. Could you please give me some tips how to make it work properly? :( I wanted just one little button and it

How can I use BoxLayout to do this?

邮差的信 提交于 2019-12-02 05:26:41
问题 I've already set up the menu (the centre boxes) perfectly, but I don't know how I can position the label. Currently what is happening is the label is going below the menu options, and the menu options are pushed to the right. Here is what I want to happen: And here is what is happening: Currently I have my boxes centred with: this.setAlignmentX(Component.CENTER_ALIGNMENT); And I have attempted to do the same with my label using: this.setAlignmentX(Component.BOTTOM_ALIGNMENT); this

Java Layout not showing components (sometimes)

*爱你&永不变心* 提交于 2019-12-02 04:57:34
I'm writing a MathQuiz for my pupils including JLatexMath for rendering and jinput for the buzzers. The problem is, that sometimes (like every fourth time) when I start the program, none of the components are visible. They appear after resizing the JFrame. First I was thinking of Bugs in the jinput or jlatexMath libraries, but I do get the same Error even with this minimal Code: public class Shell extends JFrame{ private JButton button1; private JButton button2; private Formula formula; public Shell() { super("blaBla"); this.setSize(800, 600); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Java Swing (BoxLayout) alignment issues

被刻印的时光 ゝ 提交于 2019-12-02 02:57:28
I am extremely new to Java Swing, and I'm having quite a bit of issues getting a nice layout going. I have checked out google, and even other answers on this website, but no information I find seems to solve the issue. Here is the result of my efforts: As you can see, the label, text field, and button are all out of alignment. It is my goal for all of them to have the same left-hand border, and for the button and text field to have the same right-hand border, with these left and right hand borders being each the same distance from the left and righthand sides of my window. Here are the