layout-manager

How do I center a JTextfield

一世执手 提交于 2019-12-01 05:06:04
问题 I'm having trouble centering a JTexfield in my program.The Textfield does not appear aligned with the JButton. I've tried using the x.setHoriontalAlignment(JTextfield.CENTER); but to no avail. Any ideas? import java.awt.Color; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JTextField; import javax.swing.JPanel; import java.awt.Container;

CardLayout with different sizes

亡梦爱人 提交于 2019-12-01 03:35:55
问题 Well I'm having some troubles by making a CardLayout with different sizes on each card. After reading The Use of Multiple JFrames: Good or Bad Practice? I noticed I was doing things in a way that is not the apropiate, so I decided to start learning how to use CardLayout I have tried this answer from @HovercraftFullOfEels This one from @mKorbel And finally the answer of @Kleopatra All of them are based on Hovercraft's answer but with some changes. I was able to create the CardLayout (and still

Java GUI Layouts

别等时光非礼了梦想. 提交于 2019-12-01 01:13:41
Could somebody tell me which java layout I need to use to achieve the layout below: I am currently playing out with the FlowLayout however I can’t get the entry fields to line up beside the output window: Apologies if this is a simple question this is my first time using java. Here is my frame code: private void makeFrame() { setLayout(new FlowLayout(0)); JPanel panel1 = new JPanel(); JPanel panel2 = new JPanel(); JPanel panel3 = new JPanel(); JPanel panel4 = new JPanel(); JPanel panel5 = new JPanel(); JPanel panel6 = new JPanel(); JPanel panel7 = new JPanel(); panel1.setLayout(new FlowLayout

Grid bag layout not displaying the way I want

房东的猫 提交于 2019-12-01 00:01:54
So I have 6 panels, all of them used a grid layout. And I put them together using gridbaglayout, here is the design I wanted Turn out it became a total mess The "second" panel became much further away to the right The third panel is squeezed a lot to the left and it was a disaster. Here is my code for the gridbag layout c.gridx = 0; c.gridy = 0; add (first,c); c.gridx = 2; //so that the second panel starts from the center and is divided evenly with the first panel add(second,c); c.gridx = 0; c.gridy = 1; add(third,c); c.gridx = 1; add(fourth,c); c.gridx = 2; add(fifth,c); c.gridx = 3; add

Swing: column-flow layout manager?

时光毁灭记忆、已成空白 提交于 2019-11-30 21:34:29
I'm looking for a LayoutManager that will allow me to show a set of components in a container (e.g. a JPanel), in columns, roughly as follows. The container's width is an input constraint. The container's preferred height is a function of the width, and is either: the minimum height needed to get the components to fit within the width, when laid out in more than one column. the minimum height needed to get the components to fit in a single column. The components will be placed in a newspaper-column order, from top to bottom and then from left to right. Here's an example (low-tech text display)

How to overlay, resize and centre a component on a JPanel?

穿精又带淫゛_ 提交于 2019-11-30 21:15:43
I've spent a while reading and experimenting here, and come up with a few approaches, but not got any of them to work completely yet, so I would like to know what more experienced Swing programmers would do. The main window of my application contains a custom subtype of JPanel, which is used to display an image calculated from a mathematical function. This can take some time to calculate, so while this happens I display a text message and a progress bar superimposed on the middle of the panel. I would like both the text and the progress bar to resize appropriately when the panel is resized,

java GridBagLayout anchor

无人久伴 提交于 2019-11-30 20:46:33
Learing GridBagLayout, The issue here is, the name label and combox don't show up on the top of the panel, but I have set its anchor to NORTH. Why ? import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.GridLayout; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.WindowConstants; public class Test2 { public Test2() { JFrame frame = new JFrame(); frame.setTitle("test"); frame.getContentPane().setLayout(new GridLayout(1,2)); frame.setSize(800, 600); JPanel panel1 = new JPanel(); panel1

Java GUI Layouts

拥有回忆 提交于 2019-11-30 19:08:57
问题 Could somebody tell me which java layout I need to use to achieve the layout below: I am currently playing out with the FlowLayout however I can’t get the entry fields to line up beside the output window: Apologies if this is a simple question this is my first time using java. Here is my frame code: private void makeFrame() { setLayout(new FlowLayout(0)); JPanel panel1 = new JPanel(); JPanel panel2 = new JPanel(); JPanel panel3 = new JPanel(); JPanel panel4 = new JPanel(); JPanel panel5 = new

How can I control the width of JTextFields in Java Swing?

左心房为你撑大大i 提交于 2019-11-30 17:25:30
I am trying to have several JTextFields on a single row, but I don't want them to have the same width. How can I control the width and make some of them wider than others? I want that they together take up 100% of the total width, so it would be good if I could use some kind of weigthing. I have tried with .setColumns() but it doesn't make sense. Here is an example, where I am using three rows with three strings that should appear as in columns: import java.awt.GridLayout; import javax.swing.BoxLayout; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JPanel; import

Swing: column-flow layout manager?

僤鯓⒐⒋嵵緔 提交于 2019-11-30 17:18:26
问题 I'm looking for a LayoutManager that will allow me to show a set of components in a container (e.g. a JPanel), in columns, roughly as follows. The container's width is an input constraint. The container's preferred height is a function of the width, and is either: the minimum height needed to get the components to fit within the width, when laid out in more than one column. the minimum height needed to get the components to fit in a single column. The components will be placed in a newspaper