All Questions

Tagged with
Filter by
Sorted by
Tagged with
10 votes
3 answers
31k views

Is there any way to force GridLayout to leave empty cells?

I have a JTabbedPane with 2 JPanels set to GridLayout(13, 11). The first JPanel has enough of the cells filled out that it leaves the empty cells. The second JPanel has significantly fewer cells ...
Pentarctagon's user avatar
8 votes
6 answers
13k views

Invisible components still take up space JPanel

I have a series of components underneath each other in a JPanel set as a GridLayout. I need to temporarily hide the components but setVisible(false) doesn't cut it, because there is still an empty gap ...
David's user avatar
  • 15.9k
6 votes
3 answers
4k views

How to use MouseListener to find a specific cell in a grid

I'm trying to create a Java game with a 10 x 10 grid made up of cells. The Grid looks liks this: public class Grid extends JPanel implements MouseListener { public static final int GRID_SIZE = 10;...
Andrew Martin's user avatar
5 votes
1 answer
3k views

How to automatically increase or decease size of JButton text based on the size of JButton?

I am trying to increase/decrease the font size of JButton text automatically (if JButton increases/stretches its text will also increase, if JButton decreases its text will also decrease). The default ...
jadrijan's user avatar
  • 1,436
4 votes
2 answers
17k views

Adding buttons using gridlayout

I'm trying to create a simple tic tac toe board made by 9x9 JButtons. I used a 2d array and a gridlayout but the result is nothing, a frame without any button. What I'm doing wrong? import java.awt....
Imri Persiado's user avatar
4 votes
2 answers
5k views

GridLayout wrong number of columns

I'm trying to create panel with a GridLayout(7,2) membersPanel = new JPanel(new GridLayout(7,2)); However, when I add the components (Labels, Combobox, textfields, etc) the components show up in 3 ...
SaintLike's user avatar
  • 9,319
4 votes
3 answers
266 views

Unable to set BoxLayout(JPanel) correctly in GridLayout/FlowLayout

I have a panel with the below code public class PhotoBox extends JPanel { private JLabel photoIcon; private JLabel photoName; private JLabel print; private ImageHelper imageHelper; ...
ItachiUchiha's user avatar
  • 36.5k
4 votes
2 answers
855 views

Java: How to nest JPanel in a GridLayout?

I want to know how to nest JPanels using a GridLayout. This is how it should look like. I approached this problem by 2 ways so far, using JPanels and using JLabels, and none of them worked (only ...
HishamGarout's user avatar
  • 1,763
3 votes
1 answer
2k views

JMapFrame and GUI [Java]

Ok,hello everyone, First I'll show what I have: I have this code: public static void main(String[] arg) throws IOException { map = new DefaultMapContext(); map.setTitle("Visualizador UD - ...
Castiblanco's user avatar
  • 1,200
3 votes
2 answers
3k views

JScrollPanes scrollbars not showing up

So, I have a grid layout which stores JScrollPane's in each cell. These are also put into an array for other purposes. The "View" extends "JPanel" so it's just a regular panel with image support. The ...
Patrick.SE's user avatar
  • 4,534
2 votes
2 answers
4k views

swing - get component clicked on JPanel

OK so I've got a JPanel with a GridLayout. Each cell of the grid then contains another JPanel. What I'd like to be able to do is have a listener on the "underneath" JPanel which then tells me which ...
Morris Fauntleroy's user avatar
2 votes
1 answer
10k views

Update Grid in GridLayout

I have an array of objects laid out through a GridLayout in a JPanel. I need to be able to recreate the object in an index in the array and have the GridLayout update to reflect this. As of yet, I ...
Tanner's user avatar
  • 1,214
2 votes
1 answer
1k views

JLabel not Truncating Within JPanel

If I put a JLabel inside of a JPanel with no rigid boundaries, it does not truncate the text when the JPanel is sized to be smaller than the text. Why does this happen? Shouldn't the JPanel realize ...
Scott Hetrick's user avatar
2 votes
2 answers
940 views

How to put an image in a specific JPanel?

I am experimenting with board games lately and now I am making a Checkers board game. However I cannon figure out how to display a chip in a cell of the GridLayout. Each cell has it's own JPanel that ...
Trifecta's user avatar
2 votes
1 answer
109 views

Return an array of what GridLayout contains

I have a JPanel with GridLayout of JButtons. There is a number of operations happening inside this panel, where buttons get enabled and disabled a few times. Now I am creating some JUnit tests and in ...
El_o.di's user avatar
  • 821
2 votes
2 answers
4k views

Java Swing Gridlayout: Accessing Specific Coordinate

I'm creating a Java swing GUI and I have formatted a JPanel to use a GridLayout. I need to access a specific "box" (i.e. specific coordinate) of the grid, but I cannot see a way to do so. How can I ...
kubasub's user avatar
  • 455
2 votes
1 answer
52 views

Error when I tried to run my Java class on another computer?

I am notdoing a school project, so please do not be alarmed. I am doing some private programming to brush up. My program, a program of type .java, creates a form that asks for the boundaries and ...
RobertX's user avatar
  • 23
2 votes
2 answers
738 views

Resizing panels in a GridLayout

I want this: My frame is a GridLayout (3,2), and all I can have is this: I put the button in a panel, I think it's easier. But how can I change the size of the grid?
user2144555's user avatar
  • 1,313
2 votes
1 answer
1k views

JPanel: extra spaces between borders of nested GridLayout tables

I'm working on my first Java Swing project (really my first GUI project, unless you count client-side web programming), and I'm having an aesthetic issue. I'm making a Sudoku board in a JPanel. The ...
Rich Starbuck's user avatar
2 votes
1 answer
4k views

Width and Height of JPanel inside Container of JFrame is 0, why?

I am having a simple problem I guess, that u should know how to solve.. I am trying to do this: I have a JFrame. Then I create a JPanel and set his layout to GridLayout(5,5) Finnaly I add this JPanel ...
TiagoM's user avatar
  • 3,506
1 vote
4 answers
5k views

Adding JPanels through a loop

Made it work! Thank you guys! The code follows. I used BoxLayout since I thought it'd be ideal for stacking questions one on top of the other, but now I got issues with the layout... When I stack ...
JLA's user avatar
  • 329
1 vote
3 answers
17k views

Java grid layout and JPanel

I have a question. I have the following program and I'm having trouble with one thing. I have created a grid layout, and I'm using JPanel to enter buttons and text with in the grid, but everything ...
arled's user avatar
  • 2,622
1 vote
1 answer
425 views

GridLayout not working in JPanel

I'm trying to add a JButton to my JPanel multiple times using a GridLayout. For some reason though, every time I run the program it only shows 1 button. Here's the code: jPLeft = new JPanel(); ...
Callum Singh's user avatar
1 vote
2 answers
227 views

Why does GridBagLayout provide strange result?

I want the various components to spread out and fill the entire window. Have you tried anything else? Yes, I tried GridLayout but then the buttons look huge. I also tried pack() which made the ...
An SO User's user avatar
  • 24.8k
1 vote
1 answer
4k views

(Java) Using GridLayout (possibly GridBagLayout) on a 2D array of JPanels

I am trying to make a program that allows the user to change the colour of JPanels through mouse interaction. I have the array of JPanels all up and running (5x5) BUT they expand to fit the entire ...
Kamon241's user avatar
1 vote
1 answer
314 views

JPanel displaying weird error when drawing image

I'm having a weird error with my board game. The board consists of a 2D array with GameTiles, which is a subclass of JPanel. It all works perfectly fine when I have the size (600,500) but whenever I ...
Oakin's user avatar
  • 143
1 vote
1 answer
322 views

Grid of jpanels (for connect four game) - paintComponent only works for top left panel

I'm trying to make a simple connect four GUI by using a grid of JPanels each of which paints a colored disk when the button below them is pressed and the panels under it are full. Before adding the ...
Dan's user avatar
  • 25
1 vote
1 answer
2k views

How to center align everything in JPanels having GridLayout

Recently,I had asked a question about how to make JPanels align from top to bottom in a JFrame. Users told me to use GridLayout(). I got everything working,but I forgot to mention that I wanted to ...
Spikatrix's user avatar
  • 20.3k
1 vote
1 answer
271 views

JPanel GridLayout not adding components

I am trying to create a GUI using JPanels that have a GridLayout. The fromPanel works perfectly, but the toPanel will only add the JTextFields. The code for the panels is almost exactly the same so I'...
Sarah Kirby's user avatar
1 vote
1 answer
413 views

Arranging JLabels on JPanel when some of them need to be inside grid layout and some of them are not

I want to place a game board in JPanel and i'm using GridLayout 10x10 In addition i want to place additional labels on the same JPanel but not inside the grid. When i'm adding this labels they are ...
alonp's user avatar
  • 1,307
1 vote
4 answers
6k views

Components in GridLayout wit JPanel fills the grid incorrectly

I am trying to prevent the GridLayout in a JPanel from filling the cells entirely and ignoring any setSize of the components i am using this code: import javax.swing.*; import java.awt.*; public ...
Doron Sinai's user avatar
  • 1,186
1 vote
2 answers
196 views

How to mouse enter and mouse exit on JPanel GridLayout?

I have problem how to make mouse exit and mouse enter in GridLayout on JPanel which contain 2 Panels in 1 cell. I don't know how to know which cell was enter on a grid layout, is there any function? ...
Katherine Ryn's user avatar
1 vote
1 answer
96 views

how can I split a frame between two frames?

I am using grid layout in a frame and I want to put two panels in this frame in which one of them takes one third of the frame size and the other two third of the screen, how can I do that? I have ...
flashdisk's user avatar
  • 3,710
1 vote
2 answers
1k views

How to insert JPanel beside a grid?

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....
Eman Rabiah's user avatar
1 vote
1 answer
71 views

Panel over a GridLayout Panel

Is it possible to show a Panel (e.g. Panel-A which is nearly transparent) over a panel that has a GridLayout of images? JPanel mainPanel = new JPanel(new BorderLayout()); JPanel gridOfImages = new ...
Rapharlo's user avatar
1 vote
2 answers
7k views

How can I set a JPanel maximum or preferred size that uses gridLayout?

I had problem using a very simple frame containing two JPanel. The problem is on the layout of the Center JPanel that contains four JButton. How can I set a better size for buttons or directly for ...
soneangel's user avatar
  • 621
1 vote
1 answer
94 views

How can I make my grid populate all cells?

I am using a for loop to populate an 8x8 grid with two different buttons randomly. I have an array of instances of the buttons and for some reason, it is only giving me one of each button and not ...
rebekah.ann's user avatar
1 vote
2 answers
896 views

Using FlowLayout manager to keep 3 panels in distinct rows

I used a GridLayout mananger to create my gui, but I don't like the extra space that makes my buttons look tiny. My GUI I want it to look more like this one. Good GUI I have tried placing the first ...
grant2088's user avatar
1 vote
1 answer
1k views

How can I add labels in specific cells of a GridLayout Panel in Java?

public class TestPane extends JPanel { public TestPane() { setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); ImageIcon grassIcon = new ...
helpme's user avatar
  • 35
1 vote
2 answers
117 views

GridLayout is not displaying in JFrame

I have a GridLayout(2,1) made up of two more GridLayouts(8,4). I added the (2,1) layout to my main JFrame but when I run it only one of the 8,4 Layouts shows up. What I want to happen is both of them ...
spidey345's user avatar
1 vote
1 answer
34 views

jButtons doesn't add correctly

For better reference I'm doing match3 (candy crush type) game. public class BoardGraphics extends JPanel { public static final int WIDTH = 400; public static final int HEIGHT = 400; private static ...
Arnas Petruškevičius's user avatar
1 vote
1 answer
192 views

Swing - huge spaces between objects

I am creating a program using java swing components. when using the components i am creating a text editor. i am using buttons instead of a menu to be able to load/save. when i am trying to implemet ...
user avatar
1 vote
1 answer
136 views

Please Help:Grid of JButtons in a JPanel shows one JButton instead of 400 when GridLayout(20,20) is used

Thank you for trying to help me. I want to create a grid of 20*20 squares.It is for my A-Star Algorithm Demo. For experiment purpose I wrote the following code: import javax.swing.*; import java.awt....
Swagato Chatterjee's user avatar
1 vote
2 answers
132 views

Why are my child-JPanels being shifted or misplaced in the parent JPanel?

I have a JFrame, with one main GamePanel: import javax.swing.*; public class GameFrame extends JFrame { public static void main(String[] args) { JFrame gameFrame = new JFrame( "...
Alex Silverman's user avatar
1 vote
1 answer
6k views

How to fit a JTable into a JPanel and make it auto resizeable?

i'm adding a JTable into a JPanel wich is using a GridLayout but i don't get the same behavior like when you add a JButton... I want to know how can i get the same auto resizing behavior with my ...
mrgamertag's user avatar
1 vote
1 answer
54 views

jpanel cannot make gridlayout with 7 rows and 2 cols

i want to ask if anything goes wrong with my code. i've set my frame with borderlayout . and on the center part, i want to use gridlayout with 7rows and 2 cols inside them. paneltengah= new ...
Cignitor's user avatar
  • 1,021
1 vote
0 answers
3k views

How to add space in GridLayout in JPanel?

I am new to Java and learning GUI now a days. I want to add space on top of may FirstPlayer name I am using JPanel with GridLayout but when I add invisible box as the first element to set my elements ...
Ahsan Rafiq's user avatar
1 vote
3 answers
234 views

Jbuttons won't organize in a grid layout until i click on another window

I am making a chess game and I'm somewhat new at java so forgive me if this ends up being a result of my own stupidity, but I'm having a problem setting up the JFrame where the JPanel will show all ...
austinphilp's user avatar
0 votes
2 answers
217 views

GridLayout only updates when window is manually resized

I have a panel using a 3x3 GridLayout, which I want to change to a 4x4 layout with the click of a radio button. This is the panel class where I set up my menu and needed buttons. Please keep in mind ...
Omar Sharaki's user avatar
0 votes
2 answers
309 views

Panel fills the window in Java swing

I've added two 10x10 grids in a window but I cannot get them to appear in a smaller size. They just fill the entire window. How do I place both of them neatly in the middle in a smaller size so that ...
Phebos Belmont's user avatar