boxlayout

BoxLayout: can't setup child component size

谁说我不能喝 提交于 2021-02-05 09:32:13
问题 I have a JFrame - SuperTest and JPanel - SuperLogin . The login panel has the username and password input fields and a login button. I want it to look like this: but it looks like the pic below, with input fields having too huge height and width. SuperTest.java : import javax.swing.*; public class SuperTest extends JFrame { public SuperTest() { add(new SuperLogin()); setVisible(true); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); setSize(600, 400); } public static void main(String[

This GUI is displaying nothing after setting BoxLayout

女生的网名这么多〃 提交于 2020-12-13 04:34:57
问题 import javax.swing.*; import java.awt.*; import java.awt.event.*; public class GUI_Borrower extends JFrame implements ActionListener { JPanel panel = new JPanel(); JLabel lblName = new JLabel("Name:"); JLabel lblProg = new JLabel("Program:"); JLabel lblId = new JLabel("Library ID: "); JLabel lblTitle = new JLabel("Add Borrower"); JTextField txtName = new JTextField(10); JTextField txtProg = new JTextField(10); JTextField txtId = new JTextField(10); static int counter = 19000; JButton

This GUI is displaying nothing after setting BoxLayout

末鹿安然 提交于 2020-12-13 04:34:25
问题 import javax.swing.*; import java.awt.*; import java.awt.event.*; public class GUI_Borrower extends JFrame implements ActionListener { JPanel panel = new JPanel(); JLabel lblName = new JLabel("Name:"); JLabel lblProg = new JLabel("Program:"); JLabel lblId = new JLabel("Library ID: "); JLabel lblTitle = new JLabel("Add Borrower"); JTextField txtName = new JTextField(10); JTextField txtProg = new JTextField(10); JTextField txtId = new JTextField(10); static int counter = 19000; JButton

Creating a space for Graphics2D drawings

故事扮演 提交于 2019-12-31 07:33:08
问题 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

Creating a space for Graphics2D drawings

荒凉一梦 提交于 2019-12-31 07:32:20
问题 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

BoxLayout draw all widget in the corner

自闭症网瘾萝莉.ら 提交于 2019-12-25 10:51:06
问题 I'm trying to draw different widget in a box layout. But if I try to draw some class, which extend widget, implemented by myself, the BoxLayout draw everything in the low left corner. Trying to change size_hint and the size of the root didn't give any result. BoxLayout: orientation: 'horizontal' Button: text: 'a' Label: text: 'b' Button: text: 'c' TextInput: text: 'd' Works BoxLayout: orientation: 'horizontal' Widget: Button: text: 'a' Widget: Label: text: 'b' gives problem. Any ideas? 回答1:

set custom location for a component in box layout

喜夏-厌秋 提交于 2019-12-24 14:55:20
问题 I have a frame, inside this frame I have a panel with box layout, inside this panel I have 4 more panels. mainFrame = new JFrame("Basket Game"); mainPanel = new JPanel(); mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); mainPanel.add(options); mainPanel.add(pname); mainPanel.add(info); mainPanel.add(gamearea); mainFrame.setContentPane(mainPanel); mainFrame.pack(); mainFrame.getContentPane().setBackground(Color.LIGHT_GRAY); mainFrame.setResizable(false); mainFrame.setVisible

Keep BoxLayout From Expanding Children

不打扰是莪最后的温柔 提交于 2019-12-23 21:28:56
问题 I want to stack some JComponents vertically inside a JPanel so they stack at the top and any extra space is at the bottom. I'm using a BoxLayout. The components will each contain a JTextArea that should allow the text to wrap if necessary. So, basically, I want the height of each of these components to be the minimum necessary for displaying the (possibly wrapped) text. Here's a contained code example of what I'm doing: import javax.swing.*; import java.awt.*; public class TextAreaTester {

Java Layout not showing components (sometimes)

青春壹個敷衍的年華 提交于 2019-12-20 04:23:35
问题 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;

Dynamically growing JPanel with BoxLayout (on a null layout)

独自空忆成欢 提交于 2019-12-19 12:07:21
问题 I have a JPanel with a vertical BoxLayout on top of a JPanel with a null layout. I would like the JPanel with the BoxLayout to grow as the components are being added. See this code: public static void main (String[] args) { JFrame f = new JFrame(); f.setSize(500,500); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel total = new JPanel(); total.setLayout(null); total.setSize(f.getWidth(),f.getHeight()); total.setBackground(Color.green); JPanel box = new JPanel(); box.setLocation(100