gridbaglayout

How do I get a JPanel with an empty JLabel to take up space in a GridBagLayout

瘦欲@ 提交于 2019-12-10 14:05:19
问题 I am working on a GUI for a project at school. I am using a GridBagLayout in swing. I want to have a label indicating the input(a type of file @ x = 0, y = 0), followed by another label(the actual file name once selected @ x = 1, y = 0 ), followed by a browse button for a file chooser( @ x = 2, y = 0 ). The label at (1,0) is initially blank, however I want the area that the text will occupy to take up some space when the label contains no text. I also want the space between the label at (0,0)

GridBagLayout gridding not working

这一生的挚爱 提交于 2019-12-10 13:55:36
问题 I am trying to create the following GUI: but the GUI that I make is: What my grid looks like: image: THE GRIDLAYOUT FOR THIS I don't understand why I am getting this output since I have drawn a diagram to aid the code and it seems to work out. The method addComp adds adds the input component to the input panel at a given (x, y) position and at a given component width and height. Code: import javax.swing.*; import java.awt.*; public class GUIError extends JFrame { //initialise all the

Setting up a maximum component size when using GridBagLayout in java

a 夏天 提交于 2019-12-10 13:48:45
问题 My problem is the following : I'm trying to have a JScrollPane resizing with the window, up to a certain size horizontally, where it should stop trying to grow with the window. Can I do that with a GridBagLayout ? If so, how ? 回答1: One way to do that is to wrap you scrollpane in another JPanel with a BoxLayout and set a MaximumSize on your scrollpane which BoxLayout will enforce: Packed: Stretched (max width has been set to 700 px): import java.awt.Dimension; import java.awt

GridBagLayout: How to set fixed column width?

╄→гoц情女王★ 提交于 2019-12-10 13:36:52
问题 I've been trying to set fixed column width in the following code for ages...The thing is that when I add a label to the panel on the left, then the width is incremented automatically...and i Would like the column width to be fixed... Could anyone help me please?? This is the code: import java.awt.AWTException; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Cursor; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt

How to position components with GridBagLayout?

£可爱£侵袭症+ 提交于 2019-12-10 13:21:53
问题 I am kind of new to Java Programming and I am trying to make a window that contains two buttons and a text area, as seen in the image below. The problem I encountered though was positioning the components. I tried using GridLayout and separating the window into 9 rows and 16 cells, but then found I couldn't make components occupy more than a cell. I know I should be using GridBagLayout but I don't know how exactly. Help would be appreciated. :) 回答1: You have a number of choices. Instead of

Can components of a gridbaglayout fill parent frame upon resize?

谁说我不能喝 提交于 2019-12-10 12:54:38
问题 I've got a JFrame whose root JPanel is instantiated with a GridBagLayout . At runtime, the panel is populated with components based on some description, and the width, height and x,y coords are given in the description to be used with the gridwidth , gridheight , gridx and gridy fields in GridBagConstraints . The components themselves can be also be JPanel s with their own child components and GridBagConstraints , the GUI is described in a tree so Frame is populated recursively. The problem I

Java GridBagLayout : make component align to left

笑着哭i 提交于 2019-12-10 10:58:29
问题 I have this layout using GridBagLayout : public class Example extends JFrame { public Example() { Border outline = BorderFactory.createLineBorder(Color.black); GridBagLayout gbl = new GridBagLayout(); GridBagConstraints gbc = new GridBagConstraints(); JPanel pane = new JPanel(gbl); gbc.weighty = 1.0; gbc.weightx = 1.0; JLabel unitLbl = new JLabel("Unit"); unitLbl.setBorder(outline); gbc.gridx = 0; gbc.gridy = 0; gbc.ipadx = 30; gbc.ipady = 10; gbl.setConstraints(unitLbl, gbc); pane.add

How I can do swing complex layout Java [closed]

白昼怎懂夜的黑 提交于 2019-12-09 03:59:07
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I need a help about a java swing layout. I want do any thing like that (please see the image): http://i1374.photobucket.com/albums/ag420/Bruno_Freitas/PROGRAMADEPONTUACcedilAtildeO_zpsebaf314e.jpg I tried put a grid bag layout, but I could not insert a floatting JPanel with the content 10:00 (on image). Anyone

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

放肆的年华 提交于 2019-12-08 09:38:12
问题 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

GridBagLayout & JScrollPane: how to reduce row height?

≯℡__Kan透↙ 提交于 2019-12-08 08:03:51
问题 See below a simple test code using a GridBagLayout (2 rows, 2 component on row 0, 1 component on row 1). Although I have specified weighty to be 0.01 for first row and 1 for second row, the ratio on the screen looks more like 0.3 vs. 0.7. It seems that the height of the first row is resized so that the whole textarea fits in it. How can I reduce the height of the first row, so that the scroll bars of the JScrollPane will appear? public class Test { public static void main(String... args) {