gridbaglayout

SetVisible(false) changes the layout of my components within my Panel

萝らか妹 提交于 2019-12-04 06:55:08
How do I make the subpanels within my main panel stay where they are when I set one of the subpanels to be invisible? What I have looks like: [ (Panel1) (Panel2) (Panel3) (Panel4) ] When I do panel3.setVisible(false) it then looks like: [ (Panel1) (Panel2) (Panel4) ] I would like it to look like: [ (Panel1) (Panel2) (Panel4) ] I am using the GridBagLayout and my mainPanel declaration looks like: final JPanel panel = new JPanel(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); and I add an new panel like: final JTextField valueTextField = new JTextField(); valueTextField

Centering JLabels inside JPanels

眉间皱痕 提交于 2019-12-04 04:23:38
问题 I'm making a score-keeping program, but I'm running into a problem. What I've tried to do is have a JPanel at the top that contains two JPanels, which, in turn, contains two team names. I'm confused as to why the two JLabels at the top of the program aren't centered inside of the JPanels they're contained in. import java.awt.*; import java.awt.event.*; import javax.swing.*; public class ScoreFrame extends JFrame { private static final Dimension SCREEN_SIZE = Toolkit.getDefaultToolkit()

Small GUI issue I cannot fix. JTextFields

风流意气都作罢 提交于 2019-12-04 02:32:18
问题 Small error I can't manage to do. So right now my program GUI looks like this: Now there is a TextField under the 'Mark' column were the user can input their data. I also want the same for the weight section were I want to insert a TextField right under 'Weight' column. However when I try and put in a TextField, both the the Textfields turn like this when the window is small: and this when the window is enlarged: How can I make it so that there is a textfield under Mark AND Weight? Code:

Starting GridBagLayout from top left corner in Java Swing

柔情痞子 提交于 2019-12-04 00:41:18
I'm new to Java Swing and I have been struggling to start the GridBagLayout from top left corner so that c.gridx=0 c.gridy=0 will put my object on the top left corner. I'd appreciate if you could help me by telling what I need to do after this point: JPanel panel = new JPanel(new GridBagLayout()); frame.add(panel); GridBagConstraints c = new GridBagConstraints(); I know that I have to use NORTHWEST or FIRST_LINE_START constants, but I don't know how. I tried to do it this way' but it did not realize the constants. frame.getContentPane().add(panel, BorderLayout.NORTHWEST); Thanks for your help.

Understanding GridBagLayout constraints

喜欢而已 提交于 2019-12-03 21:23:01
I am relatively new to swing and I am trying to figure out exactly how it works. Tell me if I am wrong. I have mostly figured out gridx and gridy which is necessary to place a component. You need at least n values of (gridx,gridy) to create an nxn grid. For example (5,5),(3,3),(4,9),(3,10) will create a 3x4 gridspace(4 rows, 3 columns) with the components using the above (gridx,gridy) respectively placed in cells (3,2),(1,2),(2,3),(1,4). weightx and weighty seems to have 2 functions, a >0 value of weightx and weighy stretches the grid cells to the edges(otherwise it's centralised) and we can

Java GridBagLayout - How to position my components gap-less and one by one?

匿名 (未验证) 提交于 2019-12-03 09:52:54
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'm using GridBagLayout to place my GUI components by the following code, wanting the components lay one by one in a column, without any gaps : import java . awt . GridBagConstraints ; import java . awt . GridBagLayout ; import javax . swing . JButton ; import javax . swing . JFrame ; import javax . swing . JPanel ; public class TestGUI extends JFrame { public TestGUI (){ JPanel bigPanel = new JPanel ( new GridBagLayout ()); JPanel panel_a = new JPanel (); JButton btnA = new JButton ( "button a" ); panel_a . add ( btnA ); JPanel

java网格包布局管理器

匿名 (未验证) 提交于 2019-12-02 21:52:03
package qwer ; import java . awt . Button ; import java . awt . Font ; import java . awt . GridBagConstraints ; import java . awt . GridBagLayout ; import java . awt . event . ActionEvent ; import java . awt . event . ActionListener ; import javax . swing . ButtonGroup ; import javax . swing . JCheckBox ; import javax . swing . JFrame ; import javax . swing . JLabel ; import javax . swing . JOptionPane ; import javax . swing . JRadioButton ; public class wenjuan { public static void main ( String [] args ) { JFrame jf = new JFrame (); jf . setSize ( 550 , 650 ); jf . setLocation ( 550 , 100 );

How to set size for custom-made panel that will work with gridbaglayout?

拜拜、爱过 提交于 2019-12-02 20:01:11
问题 this is my problem, I hope you will help me somehow. I have one class that extends JPanel , and that class is creating a rectangle with a paintComponent method. When I add that class to JPanel who has gridBagLayout ,first is not appearing. But, when I set Dimension.getPreferredSize() in that class, I can see the rectangle...and the problem is when I call MouseListener and see that rectangle is only moving in little square in the frame. So I think that somehow that method getPreferredSize() is

Positioning buttons below menu bar with GridBagLayout

ⅰ亾dé卋堺 提交于 2019-12-02 18:22:25
问题 I want to add my two buttons just below to the JMenuBar . I am using a root JPanel for the entire window of the GUI, and I am adding to it different components, so far, two, the menu bar and a panel that contains two buttons. But I don't know how to place the GridBagConstraints for the panel that contains the buttons in a way that it places just below the menu bar. This is my code: JFrame f = new JFrame("Cliente AEMET"); JPanel panel_raiz = new JPanel();//root JPanel GridBagConstraints gbc =

GridBagLayout component not filling space as it should

一笑奈何 提交于 2019-12-02 17:17:12
问题 I'm making a program that uses lots of different compenents, so I've started using a GridBagLayout for it. It's working great, but when I run the program I get this: Picture of current layout It should be putting the right-most list object directly up against the rest of the objects, and filling the entire width of the screen. Not sure why it isn't. Here's a short copy of the relevant code (I put them all into one class for simplicity should you decide to run it.): import javax.swing.*;