gridbaglayout

Incorrect JPanel position in GridBagLayout

自古美人都是妖i 提交于 2019-12-11 16:45:53
问题 im using GridBag to display some JPanels with images inside a JScrollPane. When there are 3 or more images the GridBagConstraints work ok but when i have 1 or 2, they get aligned to the center of the JScrollPane instead of being in their position in the top (like in a gallery) Here is my code: JPanel jPanel1 = new JPanel(); GridBagLayout layout = new GridBagLayout(); jPanel1.setLayout(layout); GridBagConstraints gbc = new GridBagConstraints(); JPanel photo = new JPanel(); Dimension d = new

Gridbag Layout in java

懵懂的女人 提交于 2019-12-11 16:27:34
问题 I have to edit a gridbag layout problematically and i am having weird results. expected: | A | | B | | -- | | C | | D | | -- | Results: | A | | B | | D | | C | A and C have a height of 2 Is this just how gridbag works? is there anyway to force it? My program has two columns and n number of rows. It supports a width of 2 but it only comes into effect when it is in the first col. If in the 2nd row it acts as though the width is 1. gbc.gridx = 0; gbc.gridy = 0; gbc.gridheight = 1; gbc.gridwidth

JTextField not aligning in GridBagLayout

戏子无情 提交于 2019-12-11 11:44:07
问题 I've just started working with GridBagLayout , and the image below is pretty self-explanatory of the problem, I need the first JTextField of the first 4 rows to stretch all the way to the JLabel on the left, just like the right ones. The Component's grid widths, from top to bottom, are : 1, 1, 1, 1 1, 3 1, 1, 1, 1 1, 3 2, 2 2, 2 Code of the GridBagConstraints settings in the JFrame : Also, why even if I set anchor to 'NORTH', all the components still sit aligned at the center of the JPanel?

JTextFields automatically resizing

谁说胖子不能爱 提交于 2019-12-11 10:07:34
问题 I am making a program that is supposed to allow you to type in text, and it will that text in every single font on the computer. Here is a screenshot of what happens just as the fonts are loaded: Now, I realize that there are a billion other problems besides the automatic resizing of the JTextFields, but I want to focus on one thing at a time. Anyway, whenenver I scroll down in the JScrollPane, here's what happens: Could someone please tell me what I have to do with the GridBagConstraints or

JLayeredPane and GridBagConstraints

佐手、 提交于 2019-12-11 08:13:40
问题 Inspired by this question JLayeredPane with a LayoutManager I'm trying to get the JLayeredPane to work with the GridBagLayout. Here's the custom LayeredPane-class: class StackConstraints { public final int layer; public final Object layoutConstraints; public StackConstraints(int layer, Object layoutConstraints) { this.layer = layer; this.layoutConstraints = layoutConstraints; } } class LXLayeredPane extends JLayeredPane { private static final long serialVersionUID = 1946283565823567689L;

Center panel when window resized

你。 提交于 2019-12-11 07:50:12
问题 I would like to keep a panel I have created using an absolute layout in the center of my window even when the window is resized (if possible). I've come across a couple of suggestions here and [here][2] but no dice! Below is my sample code, any ideas or suggestions? I have no problems centered a single component like a JLable but I want to center a panel with many components! import java.awt.Color; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import javax.swing.JFrame;

Trying to teach myself Java GUI (Swing), should be an easy fix

。_饼干妹妹 提交于 2019-12-11 03:26:24
问题 Alright, like the title says, this should be an easy question but I'm very new to doing gui and I'm having a little problem. I'm trying to separate my window into 3 bordered sections (horizontal). So far I've got two, however, the one in the middle extends down to the bottom of the window, blocking the bottom section. I'm guessing it has something to do with my use of NORTH, CENTER, and SOUTH? I attached a picture of the window and some of my code, let me know if you need more! Top section

Specify Grid Parameter of GridBagLayout Without Component

半腔热情 提交于 2019-12-11 02:48:28
问题 I was attempting to help another user, and I came across a problem where I was wanting to do this with GridBagLayout: c1 | c2 | c3 ~10% | ~80% | ~10% v v |-------------------------------------------------| r1 | B1 | <S1> ~50% |-------------------------------------------------| ----> |--------------------------------------------------| r2 <S2> | B2 | ~50% |--------------------------------------------------| The specific problem is that I want to set the weight of c2 to be 80%, but I do not

How to make a component invisible, without changing the location of other elements

我怕爱的太早我们不能终老 提交于 2019-12-10 18:40:20
问题 There are two buttons: "Next" & "Back" to pass on the list. When the reached the end, the button "Next" to disappear, but the button "back" should not jump to her place. I use the setVisible (false) , but the button 'Back' jump to the place of the "Next". Location manager is GridBagLayout. 回答1: Place the button in a container JPanel with CardLayout together with one more empty JPanel (or JLabel). When you would like to hide the button just swap cards in the container. 回答2: I use the

Adding JScrollPane in JTextArea using GridBagLayout

久未见 提交于 2019-12-10 18:38:15
问题 I'm having an issue adding JScrollPane in JTextArea using GridBagLayout. Basically the program runs fine when the scrollbar isn't needed but the layout gets messed up and the content gets cut off when it is. The relevent code is as follows import java.io.*; import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.util.*; public class testGUI extends JFrame { public static String name; static JTextField textfield = new JTextField(30); static JTextArea textarea = new