All Questions
Tagged with grid-layout swing
419
questions
40
votes
1
answer
81k
views
How can I make my columns different sizes using GridLayout in swing?
I'm using a GridLayout and my code is as follows:
int changingVar = 1;
JPanel panel = new JPanel(new GridLayout(changingVar, 2));
panel.add(new JButton("BUTTON1"));
panel.add(new JButton("BUTTON2"));...
38
votes
6
answers
43k
views
"Comparison method violates its general contract!" - TimSort and GridLayout
I made a color palette with a jPanel and a JLabel array in it. At first it worked well, but then i put some other jLabels out of the JPanel and added them some events. Now I keep getting this error:
...
22
votes
6
answers
2k
views
Which layout can do this?
I'm trying to layout some JLabels in my application as shown in this example:
I always have this JLabel at the middle and the number of the others JLabels is variable it can go from 1 to 30. I have ...
20
votes
6
answers
77k
views
How do we show the gridline in GridLayout?
How do we show the gridline in GridLayout? in Java?
JPanel panel = new JPanel(new GridLayout(10,10));
panel.setBorder(BorderFactory.createEmptyBorder(2,2,2,2));
for (int i =0; i<(10*10); i++){
...
17
votes
7
answers
49k
views
How to get X and Y index of element inside GridLayout?
I am studying a java tutorial and saw that the way to find the x/y indexes of a JButton inside a GridLayout is to traverse a bidimensional array of buttons b which is associated to the layout and ...
16
votes
1
answer
30k
views
Java Swing GridLayout "Cell span"?
Is there a way to make a single element in a Grid layout take up more than 1 location in a grid. Example: I want to create a textbox that takes up an entire grid row, is there some way to do this?
15
votes
5
answers
126k
views
Load arrayList data into JTable
I'm trying to set items from a method called FootballClub and so far it's fine.
but then I created an arrayList from it and I somehow can't find a way to store this information into a JTable.
The ...
13
votes
1
answer
83k
views
Create a Chess board with JPanel [duplicate]
I have a simple Chess board in a JPanel with GridLayout(8,8) as layout manager.
I am trying to add panels for the fields' column name and row number.
Right now I've created another panel 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 ...
9
votes
3
answers
62k
views
Text align in JLabel [duplicate]
I've got GridLayout-JPanel. In every cell there is a JLabel with some String. How can I right-align this text in my cells?
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 ...
8
votes
3
answers
20k
views
Changing width of GridLayout
I use the GridLayout for my JPanel and was wondering, if it's possible to change the width of the columns:
GridLayout grid = new GridLayout(5,2);
panel.setLayout(grid);
Is there a simple way?
7
votes
2
answers
29k
views
Java Swing: How can I change the size of one row in a Grid layout and allow it to resize dynamically only horizontally and not vertically?
Hi everyone I have a JFrame which has three components inside.
A menu
A tabbed pane
a panel that has some buttons
Initially my goal was to create a design like the following:
when the user would ...
6
votes
3
answers
876
views
How do I create the following GUI in Java Swing?
I want to create the following GUI with Java Swing.
Since I'm not experienced enough with Java Swing, I'm not sure how to exactly recreate that GUI.
I've tried using GridLayout which looks like this:...
6
votes
5
answers
8k
views
How to fill a GridLayout top-to-bottom and then left-to-right?
The default behavior of a GridLayout is that the components are filled row by row, and from left to right. I wonder if I can use it so that the components are filled by columns (from left to right)? ...
6
votes
1
answer
4k
views
Dynamic GridLayout with fixed size
Guidance required..
Would like to achieve something like the image below whereby the child panel stays the same size but contains up to 4 components. I realize I can achieve this by changing the ...
6
votes
2
answers
22k
views
How to embed a grid layout inside a border layout in java
I have a border layout and I want to add a grid layout to the center section. However, I can't declare a grid and then add my center border. How can I do this?
public Liability_Calculator(String s)
{
...
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;...
5
votes
2
answers
28k
views
GridLayout and number of rows and columns
Does GridLayout ever not honor the number of rows and columns you've specified if you don't fill it completely?
I'm creating a GridLayout with 3 rows and 4 columns. However, I'm only adding 9 ...
5
votes
1
answer
51k
views
GridLayout java center alignment
I'm using GridLayout class in Java to layout some UI components. Image is here:
I would like to get the Create Shopping Cart picture and the associated text to be aligned center in their respective ...
5
votes
1
answer
5k
views
Swing doesn't respect my GridLayout Rows x Columns definition. How to fix?
I have been trying to resolve this without success.
How to make JPanel p respect the defined GridLayout?
All I get is the first row containing 3 panels but not 4 as I've told Java to perform.
What's ...
5
votes
3
answers
4k
views
JProgressbar width using Grid/FlowLayout
I'm working on a downloader which looks like this at the moment:
The JFrame uses a BorderLayout.
In the NORTH, I have a JPanel(FlowLayout). In the SOUTH there is also a JPanel(FlowLayout), in the ...
5
votes
2
answers
363
views
Remove huge gaps between check boxes on panel
Its pretty basic UI, but I cannot setup the JCheckBox buttons so that they are placed immediately after one another (vertically) without any spacing. How would I reduce the spacing seen below?
...
5
votes
3
answers
8k
views
GridLayout + Mouse Listener
Okay guys I have a problem, I dont know how know which cell was clicked on a grid layout, is there any function?
I have grid layout on container, for 10 rows and 10 columns, and what I want is a ...
5
votes
4
answers
4k
views
How do I neatly indent some components using Java Swing layouts
Using Swing, what is the best way to indent some components underneath a checkbox or radio button? I need to make something in the style of Firefox 3.6's Options->Privacy dialog where some checkboxes ...
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 ...
5
votes
1
answer
3k
views
Creating a contact list program
I am coding a contact list application in eclipse using Java Swing.
How can I get a simple table layout that contains just columns and rows?
I don't want row or column labels.
Something like this:
...
4
votes
3
answers
4k
views
GridLayout not honoring the number of rows I want per column
I have the following,
GridLayout layout = new GridLayout(4, 0);
In the event that I have 5 items, this will create 2 columns, where the first contains 3 rows and the second contains 2 rows. This is ...
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....
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 ...
4
votes
2
answers
4k
views
How to remove space between ImageIcons in GridLayout (Java)
I am making a java game reliant on having tiles in a grid. I have used ImageIcon, along with JLabel in a GridLayout. I have set both the vertical and horizontal to zero when I created the GridLayout, ...
4
votes
1
answer
3k
views
Centering Radio Buttons in a GridLayout
I am trying to create an application using GridLayout and I don't know how to center some radio buttons. The window ends up looking like:
Here is how I added the radio buttons:
JPanel qArea = new ...
4
votes
3
answers
4k
views
How to use GridBagLayout and GridLayout for optimum alignment?
I wanted to try out GridBagLayout in my program but sadly I don't clearly understand it, I tried implementing GridLayout also but both give me different problems. Let me show you the code and the ...
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;
...
4
votes
3
answers
7k
views
GridLayout of Buttons to Output a Checkerboard
I am programming in Java and am still rather new. Experimenting with GUI Basics, I decided to make a checkerboard with all 64 cells being instances of JButtons with a filled in background. Sadly, when ...
4
votes
3
answers
708
views
How to reduce the space between the 3 swing checkboxes?
I want to reduce the size between the components with in the Formatting group (left side on the image). How to do this?
JPanel formattingGroup = createGroupWithName("Formatting");
...
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 ...
3
votes
3
answers
45k
views
Java Swing - JPanel and GridLayout Margins/Padding
I'm working on building a chess game in Java, and I'm currently having a bit of trouble getting the GUI exactly the way I want it with Swing. I'm using a GridLayout to organize a grid of 8x8 ...
3
votes
5
answers
594
views
Java Layout Manager
I use a grid layout of 2 rows and 6 column. the first column is a label and second is combo. My problem is
according to the size of the label the combo box size also increases.
i want a stable ...
3
votes
4
answers
9k
views
Best Swing Layout for 2-dimensional grid of buttons?
I'm trying to create a JDialog like the Symbol dialog in Microsoft Word that you get by choosing Symbol... from the Insert menu. Basically, it's an n x m (n and m are not known until runtime) grid of ...
3
votes
2
answers
6k
views
Overlay images on a GridLayout in Java
Is it possible to have one set of images be the "background image" of a gridlayout and other images be the "content" of the gridlayout?
If not, what's the best way to do it?
3
votes
1
answer
10k
views
JLabel in GridLayout
How to add JLabel out of the GridLayout? I have an 8x8 grid layout.
Container content = getContentPane();
content.setLayout(new GridLayout(8, 8,2,2));
for (int f = 0; f < btnArr.length; f++){
...
3
votes
2
answers
2k
views
Java : divide the screen
I try to do a simple swing window, but with the layout it's not easy...
I mean I just want a window with 3 panels :
header with 20% of window in height
content with 60% of window in height
footer ...
3
votes
2
answers
1k
views
2D grid of JComponents (Swing)
I'm trying to make a 2D grid of JTextFields to represent a level map. I've come to the following for initializing the 2D Array of TextFields:
fields = new TextField[level.rows][level.columns];
...
3
votes
3
answers
6k
views
Java Swing Gridlayout VERTICAL constraint
Is it possible to add components in a Gridlayout verticaly ? I mean the next one above the previous one ?
Thank you
3
votes
2
answers
2k
views
How does GridPanel determine the size?
Here is a very simple Scala GUI test:
import scala.swing._
object FirstSwingApp extends SimpleGUIApplication {
def top = new MainFrame {
contents = new GridPanel(30, 20) {
contents ++= 1 ...
3
votes
4
answers
40k
views
Can you set a permanent size for a JPanel inside of a JFrame?
My current problem is that I have a JFrame with a 2x2 GridLayout. And inside one of the squares, I have a JPanel that is to display a grid. I am having a field day with the java swing library... take ...
3
votes
2
answers
2k
views
Get a button from a gridLayout
If I have elements inside my gridLayout, can I get the reference to that object, if yes, which function do I need to use? Is it good idea to perform some actions on the objects inside gridLayout? Or ...
3
votes
4
answers
5k
views
GridLayout Help in Java
I have a JPanel with the following code:
JPanel pane = new JPanel();
pane.setLayout(new GridLayout(3, 2, 10, 30));
final JTextField fileName = new JTextField();
pane.add(fileName);
JButton creater = ...
3
votes
2
answers
2k
views
Change GridLayout in Java from horizontal to vertical with event.
I have a project im working on. Im trying to change the flag layouts from horizontal to vertical on the button press. Ive added a line of code to change the grid layout under the if "Bulgaria" ...