FAQ Database Discussion Community


How can I add JLabel and JTextField to only the bottom of the center of BorderLayout?

java,swing,layout-manager,border-layout
Is there any way too add JLabels and JTextField to only the bottom half of the center border layout. For aesthetic reasons I do not want anything on the upper half and have not found any way of doing this. I am still fairly new using swing and AWT... Any...

Stacking JPanels in the same direction

java,swing,jpanel,layout-manager
I would like to stack JPanels on in the same direction. I've searched this and can't find anything. The results that show up mean "overlap". This is what I mean: I would like to stack the second JPanel underneath the first. When using: add(BorderLayout.NORTH) on both layouts it overlaps them....

Adding a JLabel above a GridLayout [closed]

java,swing,containers,layout-manager,grid-layout
I'm having a hard time with containing a GridLayout so that adding a JLabel above it won't throw off anything. I've tried a few different things but still cant seem to get it aligned right. It's a Tic Tac Toe game: package assg01; import javax.swing.*; import java.awt.*; import java.awt.event.*; public...

Alignment of items in a Java Applet JPanel

java,swing,jpanel,layout-manager,grouplayout
I'm trying to get the top right square to be the same width as the two below it and I'd like to get the JTextArea below to match width as well. Any ideas? It seems like no matter what I set the sizes to it's doing whatever it wants....

JButtons don't load on panel until hovered over?

java,swing,jbutton,layout-manager,null-layout-manager
When this is put on a frame, the buttons don't load until they are hovered over with the mouse, and then they stay up like they should. Here's the code: I've calling things like repaint() and revalidate() but none of them seem to have fixed the problem. The main and...

Java Frame problems

java,swing,layout-manager
I am developing Tetris for fun/to learn more about Java. I am having problems with the JFrame aspect of it. I have the actual game portion, which is a on the left side of the screen with the score, level, and high score to the right of this. Then, under...

How to insert JPanel beside a grid?

java,swing,jpanel,layout-manager,grid-layout
I just built this grid using (Java Swing library), and this is the code: import java.awt.Color; import java.awt.Dimension; import java.awt.GridLayout; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.*; public class TestGrid02 extends JPanel { private static final long serialVersionUID = 1L; protected static final Color SELECTION_COLOR = Color.red; private JPanel selectedPanel =...

How to align JPanel to bottom of JFrame (java swing)

java,swing,jpanel,alignment,layout-manager
Long story short, I'm making a simple audio player in Java and am starting the GUI; no events, no functionality of any kind as of yet. I'm asking how I can the JPanel with the buttons (controls), to align to the bottom center of the main window (JFrame). Here's the...

Java - I get an error when i try to use a box layout

java,swing,layout-manager,boxlayout
I was trying to create a frame using a box layout but I get a strange error: Exception in thread "AWT-EventQueue-0" java.awt.AWTError: BoxLayout can't be shared. here's the portion of code in my Jframe class that's probably causing the error: JLabel JL = new JLabel(); PongPanel pp = new PongPanel();...

JScrollPane and GridBagLayout

java,swing,user-interface,layout-manager,gridbaglayout
I want to create two non-editable textboxes (each will contain only one line) with a fixed size, but I want them to be scrollable (horizontally only) because I know the text they will contain will be very long. I want them to be below the two buttons I define below,...

how to put components in the center in a CardLayout panel

java,swing,layout-manager,gridbaglayout,cardlayout
I have a frame that has couple of panels and they change by CardLayout. Inside each panel i will have different components. To design the GUI of the panel I used GridBagLayout. But the problem is any component or Layout I use for these paneles, they all stay at the...

How to show specific scrollpane in a CardLayout?

java,swing,layout-manager,cardlayout
I have list of JPanel components. I want to open corresponding panel based on clicking a button. While clicking button, I pass the panel name. But in my case panel have more components, so I am adding each panel to JScrollPane and adding these scroll panes to CardLayout. Based on...

GridBagLayout is not adding my panel

java,swing,layout-manager,paintcomponent
I am trying to add a three panels using GridBagLayout in JFrame. When the default layout is set, the panel is added without any problem, but when layout is changed to GridBagLayout and panel is added in JFrame, then the output is an empty frame. Here is the code for...

Own layouts in Swing in Java

java,swing,jframe,jpanel,layout-manager
I need an advice how I should create my own layout. I know that I should create that from few another layouts but I want to know from which concretely. This is how i want to my layout look like: Can you help me ?...

Custom Swing layout

java,swing,layout-manager
I'm creating a game and to set up the frame the way I want it, I need to some how create a costume layout. I have tried creating multiple panels with different layouts such as Flow and Border and adding panels on the main panel but I still don't get...

Why doesn't my Jpanel borderlayout work as expected?

java,swing,jpanel,layout-manager,border-layout
I am adding 2 elements to a JPanel, a JLabel and a JButton. I would like them to appear one on top of each other, so I added them using BorderLayout.NORTH and SOUTH. The problem I have is that the JLabel JButton and are sitting next to each other horizontally...

How to define a middle line in a window and align all elements to this line

java,swing,layout-manager
The title question may be phrased not well, but I can show you an image and you'll know what I mean: As you see the layout of top and bottom panels should be independent from the centering. I tried to achieve this with BoxLayout for the main Panel and GridBagLayout...

Java AWT: Setting background of Canvas changes the background for the whole frame

java,canvas,awt,layout-manager
Why is it that changing the background color for the java.awt.Canvas, changes the background for the whole frame? I set up a Frame object as follows: public class Gui extends Frame { public Gui() { setSize(800, 600); setLocation(0, 0); Canvas cd=new Canvas(); cd.setSize(500, 300); cd.setBackground(Color.BLUE); add(cd); addWindowListener(new WindowAdapter() { @Override...

resize synchronously jPanel components

java,swing,layout,jpanel,layout-manager
I have a JFrame as follows: -------------------------| |JFrame | | | | |---------------------| | |JScrollPane | | | |jXTaskPaneContainer| | | |jXTaskPane | | | | |-----------------| | | | |jPanel1 | | | | |-----------------| -------------------------| Below you can see the layout of jPanel1: | label1 | (without title)...

JTextArea and GridBagLayout: how to avoid changing column width as we write some text?

java,swing,layout-manager,jtextarea,gridbaglayout
I would like to design a JFrame whose layout consists in 3 columns: a left column containing a text editor (I have chosen a JTextArea); center column containing a single button (JButton); a right column containing another text editor. I managed to do this using the GridBagLayout class. However, when...

Why does the first panel added to a frame disappear?

java,swing,jframe,layout-manager,border-layout
Below is an example of adding two panels to a frame. Only one panel (the 2nd, red panel) appears. Why does the first panel disappear? import java.awt.*; import javax.swing.*; import javax.swing.border.EmptyBorder; public class DisappearingPanelInFrame { DisappearingPanelInFrame() { JFrame f = new JFrame(this.getClass().getSimpleName()); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); f.add(new ColoredPanel(Color.GREEN)); f.add(new ColoredPanel(Color.RED)); f.pack(); f.setVisible(true); }...

Setting the width of a JList in a JScrollPane with GridBagLayout

java,swing,layout-manager,gridbaglayout
I have example Java Swing code below that produces the following screenshot (screenshot has been edited to make it smaller): Here is the code: import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.SwingUtilities; public class Main extends JFrame {...

Setting Layout to JPanel resets Buttons

java,swing,layout-manager
This is the result i want : http://imgur.com/tGleIly , but centered using BorderLayout. Instead, i get this :http://imgur.com/jYgjM1F . So, basically setting a layout resets my background and puts the button on the whole frame: frame.setContentPane(new Pane()); frame.getContentPane().setBackground(Color.GRAY); I've also tried this: JPanel panel = new JPanel(); panel.add(bStart); add(panel, BorderLayout.CENTER);...

Java CardLayout IllegalArgumentException [closed]

java,swing,layout-manager,cardlayout
I am making a game that uses a CardLayout to switch between four JPanels (gamePanel, startMenu, pauseMenu, and levelMenu). I'm getting the exception "java.lang.IllegalArgumentException: wrong parent for CardLayout". However, I added all the cards to panel, which has the layout manager CardLayout, so I don't understand why panel wouldn't be...

Avoid JPanel from getting over another

java,swing,jpanel,layout-manager,border-layout
I'm trying to load JPanels inside another but I can see only one, the others get hidden behind it. This is my code: pnlResultados.setLayout(new java.awt.BorderLayout()); for (int i = 0; i < cantResultados; i++) { pResultado pr = new pResultado(modelo, resultados.get(i), padre, this); System.out.println("panel"); pnlResultados.add(pr); pr.setVisible(true); } pnlResultados.setVisible(true); pnlResultados.revalidate(); pnlResultados.repaint();...

Responsive JFrame without Layout Manager

java,swing,jframe,layout-manager,null-layout-manager
I am trying to do have two button in JFrame, and I call the setBounds method of them for setting the positions and size of them and also I passed null to setLayout1 because I want to usesetBounds` method of component. Now I want to do something with my code...

create customized GUI using GroupLayout

java,swing,layout-manager,grouplayout
I'm trying to create customized interface like the one displayed by daches: ----------------------------------------------------------------- - ----------------------------------------------------------- - - - - - - ----------------------------------------------------------- - - - - ---------- - - - - - - ---------- - - - - ---------- ----------------------------------- ---------- - - - - - - - - -...

How to Position a JLabel in the specified Layout?

java,swing,jbutton,jlabel,layout-manager
I am trying to position my Labels and Button on screen. I found an answer here to set label's Position using: label3.setHorizontalAlignment(SwingConstants.CENTER); label3.setVerticalAlignment(SwingConstants.CENTER); but there has been no effect in my code. Also, on changing my layout from Flow Layout to Border Layout, only one Jbutton [CLEAR] appears on the...

How can i add JLabel and JTextArea in the same space in JAVA

java,swing,jpanel,layout-manager,jtextarea
Here is the UI that I'd like to make. I'm new to UI design. Could anyone tell me which layout should i use? How to make JLabel and JTextArea stick together and make String in the JTextArea clickable? Are there better ways to realize this design. I have tried BorderLayout,...

How to set JButton size with GridBagLayout

java,layout-manager,gridbaglayout
I want to set the size of my JButtons that are at the center of my screen to become larger but I can't seem to find how to do that using GridBagLayouts. Here is how it looks like : Here is my code : // Client c.fill = GridBagConstraints.BOTH; c.anchor...

GridBagLayout formatting in Swing

java,swing,layout-manager,gridbaglayout
When I add the second row (of buttons), my textArea disappears. Here is the GridBagLayout code: public void gridlayout(){ setLayout(new GridBagLayout()); GridBagConstraints grid = new GridBagConstraints(); grid.gridy = 0; grid.gridx = 0; add(refreshButton, grid); grid.gridx = 1; grid.gridwidth = 4; add(textArea, grid); grid.gridy = 1; grid.gridx = 0; grid.anchor...

trouble with GridBagLayout and panels

java,swing,layout,layout-manager
So what I am trying to do is create this: I am using a gridbag layout and here is what I have so far: public class board { public static void addComponentsToPane(Container pane) { pane.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); JPanel leftTop = new JPanel(); leftTop.setPreferredSize(new Dimension(251,300)); leftTop.setBackground(Color.black); c.fill...

Put 2 FlowLayouts one under another with a margin

java,swing,jpanel,layout-manager,flowlayout
I'm trying to dynamically create 2 FlowLayout instances (one of them has about 50 dynamically created buttons, other has about 10) so that there is a slight gap between them. I'm stuck with this, I tried to use BoxLayout and put flow layouts in it, and then create gap with...

How to bring the Image in Java GUI To a new line?

java,swing,layout,awt,layout-manager
I am trying to make a simple gui window with images. Here's my code: import java.awt.*; import javax.swing.*; public class Image extends JFrame { private ImageIcon [] image = new ImageIcon[10]; private JLabel [] label = new JLabel[10]; Image() { setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); for(int i=0; i<10;...

Java Swing GridBagLayout - adding buttons without space

java,swing,layout-manager,gridbaglayout
How can I remove spacing caused by gridBagLayout and make them stick together? Here is my code simply adding 3 buttons. I read this question but there was no complete solution How to fix gap in GridBagLayout; I just want to put all of my buttons on the top of...

When typing into JTextArea, text in JLabel moves

java,swing,layout-manager
I'm making a simple GUI and have a problem. This is my code : JFrame jFrame = new JFrame(); jFrame.setTitle("Simple Editor"); jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jFrame.setLocation(50,50); jFrame.setResizable(true); Box box = new Box(BoxLayout.Y_AXIS); JTextArea jTextArea = new JTextArea(); jTextArea.setPreferredSize(new Dimension(470,500)); JLabel jLabel = new JLabel(); box.add(jTextArea); box.add(jLabel); jLabel.setText("Font type : " + Main.fontType +...

JScrollPane does not work on JPanel

java,swing,jpanel,jscrollpane,layout-manager
I have a frame that contains a mainPanel. This last will add other commandPanels (each one contains a button and a textField) Dynamically. the problem is that the JScrollPane does not appear to let me use the unseen commandPanels even if the mainPanel is full. The below picture shows my...

Creating a method for settings of GridBagConstraints

java,swing,methods,layout-manager,gridbaglayout
I have couple of components that each hold 4/5 lines of code regarding their settings in the GUI. so I thought it would be better if I create a method for those settings so they don't repeat for every component. Here is my example code for one component: GridBagConstraints c...

JDialog layout issues

java,swing,layout-manager,jdialog
I'm using a JDialog to create a customized dialog box for my Java project. I'm having issues with the layout at the moment. It seems each JLabel I add to the dialog goes over the existing one. Do I need to add some sort of JPanel? I also seem to...

More than 2 Visible JPanels in a CardLayout

java,swing,jpanel,layout-manager,cardlayout
I am facing problems while placing more than two JPanel objects in a CardLayout which are visible at the same time. Although I can place a number of panels, but they do not appear simultaneously and I cannot resize them as I want. For a more clearer view about what...

Trying to figure out the CardLayout

java,swing,jpanel,layout-manager,cardlayout
I'm trying to work out how to use the CardLayout but I keep getting "wrong parent for CardLayout" errors and such. I've never used CardLayout before and I can't seem to find a lot online. I just need to be able to switch between two panels on the frame. Thanks...

Using the GridBagLayout

java,swing,layout-manager,gridbaglayout
I have never used layouts before and from what I understand GridBagLayout is probably not the easiest layout to start on, however I am trying to use it anyway. I am trying to use the GridBagLayout for my JPanel so that when I re-size it the components grow. I only...

GridBagLayout Not Working Properly?

java,swing,jframe,layout-manager,gridbaglayout
I am using a GridBagLayout for my components in a JFrame. I just started using it, and I keep confusing myself. What I want is; Patch notes in the top left, buttons (vertical) on the right, play button on the bottom. I'm not sure what the issue really is, but...

How to get JTabbedPane in JSplitPane to fill the whole window?

java,swing,awt,layout-manager
My JTabbedPane is in a JSplitPane in a JPanel, like this, but I don't want it to be small like that: I want it to look like this: How do I do that? Here is my code: Tabbed_Tables.java public void setupWidow(){ JPanel left = new JPanel(); JPanel right = new...

How to make components in a JPanel strectch as far as possible?

java,swing,jpanel,components,layout-manager
I'm trying to create a simple swing program that lets the user play with a circle. Here is my code: import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JButton; import javax.swing.border.Border; import javax.swing.BorderFactory; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import java.awt.Color; import java.awt.Graphics; import java.awt.FlowLayout; import java.awt.BorderLayout; public class SixthProgram { public static...

JPanel, problems with resizing

java,swing,jpanel,layout-manager
I'm a newbie. Trying to make auto resize border. I made border on my frame with 2 panels. I added panels with border into first panel. I want border which retreated from all edges. In this border panel I also added text panel and button. When I expand the window,...

Java: What Layout Manager would be best for a game menu?

java,swing,layout-manager
=================== Game Name Play Exit =================== the above is what my previous game menu looked like. I used the Box Layout to create it but it was very tedious. Is there there a better layout manager that I could use? here is the code for those that asked of the...

GridBagLayout not getting expected result

java,swing,layout-manager,gridbaglayout
Trying to understand how the GridBagLayout for Java works. Never used it before so its probably a stupid error that I've made. My objective is to place a JLabel at the top center of the page. I've been using the java tutorials on Oracle but have had no luck. It...

GridBagLayout alignment and Button style

java,swing,layout-manager,gridbaglayout
I am trying to align a button using the GridBagLayout but it look I just can't achieve that. Also I want to remove the JButton's texture from my custom button, but I can not.. This is what it looks like: I want the buttons to be at the top( but...

setLocation on a JButton doesn't seem to work as expected

java,swing,position,jbutton,layout-manager
Here is my shortened version of my code: JPanel card1 = new JPanel(); JLabel switch1 = new JLabel(new ImageIcon("switch1.jpg")); switch1.setLocation(TOPSWITCH, LEFTSWITCH1); JLabel switch2 = new JLabel(new ImageIcon("switch1.jpg")); switch2.setLocation(TOPSWITCH, LEFTSWITCH2); JLabel switch3 = new JLabel(new ImageIcon("switch1.jpg")); switch3.setLocation(TOPSWITCH, LEFTSWITCH3); card1.add(switch1); card1.add(switch2); card1.add(switch3); card1.setBackground(Color.BLACK); /* JButton goToRoom = new JButton("TEST"); goToRoom.setLocation(180,...

trouble with creating JTable to display data [closed]

java,swing,jtable,layout-manager
I am doing this payroll project for school. The idea is for the user to input the employee's name, work hour, hourly rate, and select department from the ComboBox. There will display 3 buttons, "Add More", "Display Result", and "exit". "Add More" button will store the input into several arryalist...

How to add a cardlayout format to my main game screen so that when I click a button it changes from Main Menu screen into my Game Screen Code Provided

java,swing,layout-manager,cardlayout
I'm making a game of checkers for my A2 Computing coursework which is due in within a week. I have completely finished the game, and only thing I have left to do is connect the two JPanels together via a CardLayout that I have made. However I am unsure how...

Automatically re-sizing a component within a GridBagLayout

java,swing,layout-manager,gridbaglayout,autoresize
In this code I have a panel in the GridBagLayout which contains a JLabel and a JTextField. import java.awt.*; import javax.swing.*; public class Simple { JFrame simpleWindow = new JFrame("Simple MCVE"); JPanel simplePanel = new JPanel(); JLabel lblSimple; JTextField txtSimple; public void numberConvertGUI() { simpleWindow.setBounds(10, 10, 420, 80); simpleWindow.setMinimumSize(new Dimension(420,...

GridBagLayout don't take all the window place

java,swing,awt,layout-manager,gridbaglayout
Hi have a very simple question, why my gridBagLayout don't take all the disponible place on my window ? here the code : public class FenConnection extends JFrame { private static final long serialVersionUID = 4799549157439445680L; private String adresse; private int port; private JLabel infoLabel; private JTextField tf_adresse; private JButton...

JFrame text components not showing up properly

java,swing,jpanel,layout-manager,preferredsize
I was playing around with JFrame today and had trouble getting a JButton component to display text properly. The text displayed in JButton is cut off at the end. I tried resizing the JButton component in order to make sure that the text could fit, but the same problem occurred....

Prevent Vertical Centering of FlowLayout

java,swing,alignment,layout-manager,flowlayout
I have a JPanel using a FlowLayout layout manager and contains components with different sizes. EDIT: I want to use the FlowLayout because it allows the components to wrap to a new line when the container is resized and they no longer fit next to each other. The following image...

Dynamic width and fixed height of rows in JPanel

java,swing,jpanel,jscrollpane,layout-manager
I am trying to use Java layout managers (I have no external libraries, and am using Java 7) to create a layout where data is provided in rows, where the rows have a fixed height, but the width fills to fit the window. An example is provided below: The idea...

How set size of specified String to JTextField?

java,swing,layout-manager
JTextField in JPanel which in turn in JDialog doesn't take specified size. I tried to use BoxLayout and FlowLayout, but still have not achieved the desired size. I.E. I measure the size of String example and set this size to width of JTextField inputCat, but inputCat doesn't take this size,...

FlowLayout alignment changes are not directly visible in Swing

java,swing,layout-manager,flowlayout
When I change a property of a layout manager of a component which is currently visible in SWING the changes are not made visible. If I resize the entire frame the changes get visible. How to solve this problem? I've experimented with revalidate() and friends but without any success. Also...

How do I make a counter in a JFrame under the buttons?

java,swing,jframe,layout-manager
I am trying to work on a little program just for fun, and I want it so when I click the pineapple button it adds a pineapple to a string of text that I want under the buttons, same for rock. So basically I need a counter for the rock...

How to stop changing the position of the button?

java,swing,user-interface,layout-manager
I have this Java Swing code for some simple GUI with JButton, JTextPane and JTextField. The problem with this code is that when I try to write some text inside of the textPane (JTextPane), the openButton (JButton) start to move on the right side parallel with the text that I...

How do I center a JPanel containing a FlowLayout?

java,swing,jpanel,layout-manager
I have a JPanel containing a few components, laying them out with a FlowLayout, so that they will wrap if necessary and i want to center this JPanel in a JFrame. I tried to use a BoxLayout with a VerticalGlue, but it doesn't center it completely. Here is a simple...

GridBagLayout and JFrame Content Pane

java,swing,jpanel,layout-manager
I am currently trying to allign properly some components inside my frame. I am using GridBagLayout for it but it looks like this line is making troubles : frame.setContentPane(new ImagePanel(myImage)); I want to center the buttons in the middle but it doesnt work.If i comment it,everything works good. Also tried...

java Swing: how to keep one component left aligned with another component centered with respect to parent

java,swing,layout,jpanel,layout-manager
Say I have two components, A and B, in a JPanel. I want Component A to stay left aligned, while Component B does its best to stay in the middle of the panel. I mocked up the following demo (sorry for the quality, I made it in paint): What I...

JPanel EAST and CENTER panels seem to overlay

java,swing,layout-manager,border-layout
I've looked at multiple similar posts but none seem to have the same problem as mine, which seems relatively simple. I have the following code: public PlayScreen(Player player){ this.player = player; playScreen = new JPanel(); playScreen.setLayout(new BorderLayout()); setTowerButtons(); playScreen.add(towerButtons, BorderLayout.EAST); //line 6 setDetailLabels(); playScreen.add(detailPanel, BorderLayout.WEST); setMap("map.png"); playScreen.add(new JButton("hello"), BorderLayout.CENTER); //line...

JFrame layout helping/guide,

java,swing,jframe,layout-manager,grid-layout
I am having trouble with the layout of my JFRAME the layout is extremely difficult to me because i have just started learning it. the layout I'm looking for is select data START DAY: "textField" Month: "textField" YEAR: "textField" END DATE DAY: "textField" Month: "textField" YEAR: "textField" like it is...

GridBagLayout in my JPanel doesn't work [closed]

java,swing,layout-manager,gridbaglayout
I have a problem with a class that extends JPanel. In my game which is based on a JFrame, I have a several JPanels that I swap while program is running (login panel, new acc form panel, etc... all in one JFrame). I want to switch to Panel with GBL,...

Swing GUI with FlowLayout, won't display on JFrame more than last component added

java,swing,layout-manager,flowlayout
I am trying to display 2 panels that I have created in separate files one at the top and one at the bottom of my GUI with a button group between them. However, the window is only displaying one panel or the button group at a time. The panels and...

How do I set box layout for a nameless JFrame?

java,swing,jframe,layout-manager,boxlayout
Ok I am trying to setLayout as BoxLayout for a nameless jFrame, what do I put in place instead of 'WhatDoIPutHere?' import javax.swing.BoxLayout; import javax.swing.JFrame; public class InterestCalculator extends JFrame{ private static final long serialVersionUID = 1L; public static void main(String [] args) { InterestCalculator comp = new InterestCalculator(); comp.FrameHandler();...

Swing Panel in Panel different Layouts

java,swing,jpanel,layout-manager
I'm quite new to Swing and Java. What I tried to accomplish is panel containing and textfield and below some tags (JLabel). Unfortunately I am not allowed to post images yet. So here's a scribble of the layout I want to create and what I get: https://www.dropbox.com/s/xsfwijlp77xssmk/panel-in-panel.png?dl=0 add(textFieldTags); tagWrapperPanel =...

How to keep JPanel at top of parent container at runtime?

java,swing,user-interface,layout-manager,gridbaglayout
I create a parent container onto which I place several JPanel objects, each containing several JButton objects. I create the parent panel, add the GridBagConstraints then add each child panel to the parent: final JPanel options = new JPanel(new GridBagLayout()); options.setBorder(new TitledBorder("Select Option")); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridwidth =...

How to keep GridBagLayout from changing the size of a button

java,swing,user-interface,layout-manager
In my FlashCardPanel class, I have a subpanel,LabelPanel, with a Grid Bag Layout. It consists of a constructor with an edit button, a button to "flip" the card, and the label to display the term/definition. My problem is that every time I click my "Flip" Button to display the definition...

GridBagLayout fill empty space

java,swing,layout-manager,gridbaglayout
I used GridBagLayout. I can't figure out how to stretch the Jbuttons to fill the entire panel. I used the following: c.fill = GridBagConstraints.BOTH; Any help would be greatly appreciated. I have spent much time searching for the answer but I couldn't find it. Thank so much! Below is the...

Why my image doesn't load on contentPane except on CENTER?

java,swing,graphics,layout-manager,border-layout
I am currently still learning Java GUI and stumped on this problem. I just wonder why can't i load it anywhere except on center and how do i load my image anywhere else? import java.awt.*; import javax.swing.*; public class GUI { public static void main(String[] args) { GUI gui =...

Automatic resizing of Swing components

java,swing,layout-manager
When I compile and run my program I would like to be able to re-size it and keep the components with the same scale factor. This would mean that when the frame is expanded the components will also expand, keeping the size and the spacing scale as the original was....

GridBagLayout button.setVisible (true/false)

java,awt,layout-manager,gridbaglayout
Trying to build a really simple UI with GridBagLayout, but when using setVisible(false/true) on Easy/Medium/Hard buttons, as expected the whole thing explodes. How do I set the textfield to be on top of the Check button? I did read the doc but having hard time grasping the logic behind all...

Issues with BoxLayout in a subpanel

java,swing,layout-manager,border-layout,boxlayout
I am writing a program for a mock pizza company, and I get a BoxLayout cannot be shared error when I run my code. I am new to Layout managers and have only used Flow prior. I was working in this method at the time and I included the rest...

How to place a JButton at a specific x - y point on a JPanel

java,swing,jbutton,layout-manager
GENERAL CODE: ISSUES BELOW WILL REFERENCE CERTAIN CLASSES public class Board extends JPanel { public Board() { BoardMethods a = new BoardMethods();//BoardMethods handles logic a.printBoard(getBoard());//irrelevant to question, helps determine winner JPanel panelLORDY = new JPanel(new FlowLayout()); //JButton alphaButton = new JButton("Hi"); //alphaButton.setBounds(213,131,100,100); //add(alphaButton); } public int[][] getBoard(){ return boardEvalMatrix; }...

How to display all Cardlayouts

java,swing,layout-manager,jcombobox,cardlayout
How do I get the String from the selected card on the combo box and by using the getSelectedItem method on the fractalChooser combobox and cast the result to String? Currently it only displays one object. import java.awt.*; import java.awt.event.*; import javax.swing.*; public class FractalDriver { private static final int...

In Java Swing Null Layout, set position relative to bottom of container

java,swing,override,layout-manager,null-layout-manager
This is probably a very basic question, but I could't find anything about it online. I'm working in Java swing and have a JPanel with a null Layout Manager (ie using absolute positioning). The JPanel is filling a space in the JFrame so that its size will change when the...

GUI using applet/GridBagLayout

java,swing,applet,layout-manager,gridbaglayout
I need to create a java applet of a calculator with 2 bottoms on the top that take the whole row and under that a text area with a scroll pane and also below that 12 bottoms 4x4. Now I need to make it on an applet not on a...

JButton does not appear on the GUI

java,swing,layout,jbutton,layout-manager
when I compile and run my code everything seems to work fine except the JButton does not appear. I'm adding it to a JPanel that is on the frame. I'm new so I might not know what to lookout for here. Thanks! import java.awt.*; import java.awt.event.*; import java.text.*; import javax.swing.*;...

Fixing the size of a jButton with full screen and GridBagConstrains

java,swing,layout-manager,gridbaglayout
I am trying to have my jButton really small. It works if I change the margins (the 250 in the example). But this will not work with variable screen size. Any other method? startButton = new JButton("Start"); //this is not taking: startButton.setPreferredSize(new Dimension(50, 40)); contentPanel.add(startButton, new GridBagConstraints(0, 1, 1, 1,...