All Questions

Tagged with
Filter by
Sorted by
Tagged with
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"));...
Grammin's user avatar
  • 12k
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: ...
s.alem's user avatar
  • 12.9k
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 ...
Anis H's user avatar
  • 1,150
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++){ ...
Jessy's user avatar
  • 15.5k
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 ...
Răzvan Flavius Panda's user avatar
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?
HunderingThooves's user avatar
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 ...
jPratas's user avatar
  • 225
14 votes
5 answers
48k views

How to remove border around buttons?

I have a JPanel with the GridLayout. In every cell of the grid I have a button. I see that every button is surrounded by a gray border. I would like to remove these borders. Does anybody know how it ...
Roman's user avatar
  • 128k
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 ...
Jamgreen's user avatar
  • 10.7k
13 votes
1 answer
13k views

Don't understand how to use GridLayout.spec()

This GridLayout is going in my app that has a lot of levels. Each level has a different number of rows and columns. I assume that this GridLayout would be my best bet to use to satisfy my needs. ...
Matt's user avatar
  • 3,902
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
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?
Ariel Grabijas'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
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?
Evgenij Reznik's user avatar
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 ...
ksm001's user avatar
  • 3,852
7 votes
4 answers
14k views

Android GridLayout get row/column

I have a 3x3 GridLayout with buttons. These buttons have a onTileClicked() listener. Now I want to get the position of the clicked button in the grid. Here is my code: public void onTileClicked(View ...
VoidCatz's user avatar
  • 365
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:...
OldMcDonald's user avatar
6 votes
2 answers
15k views

What are the parameters for a GridLayout?

private static final GridLayout layout = new GridLayout( 3, 1, 1, 0 ); in this line of code what do the numbers represent and how do you use them to arrange the checkboxes and buttons in the window?
user avatar
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)? ...
skyork's user avatar
  • 7,211
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 ...
Strokes's user avatar
  • 187
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) { ...
DannyD's user avatar
  • 2,812
6 votes
1 answer
5k views

How to replace content of grid cell in SWT GridLayout?

I need to replace content of grid cell after button click. For example: there is Label and I need to replace it with Text. Is it possible with GridLayout? I need to use SWT.
alhcr's user avatar
  • 823
6 votes
1 answer
6k views

SWT: Nested Layouts with ScrolledComposite exceeds available space

I want to build a Master-Detail layout for one of my applications using SWT. Container, Content, Sidebar and Part1 are Composite instances. Scrolled is a ScrolledComposite The desired layout is ...
Johannes Wachter's user avatar
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
6 votes
3 answers
3k views

How to center content of GridLayoutManager?

Just trying to center my RecyclerView horizontal. Here is the xml: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/...
Aaron Waller's user avatar
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 ...
Paul Reiners's user avatar
  • 7,706
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 ...
Sathish's user avatar
  • 49
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 ...
Rodrigo N. Hernandez's user avatar
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 ...
Matthias's user avatar
  • 13k
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? ...
bobbyrne01's user avatar
  • 6,555
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 ...
TiagoM's user avatar
  • 3,506
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 ...
Jason's user avatar
  • 53
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
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: ...
user1644782's user avatar
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 ...
mre's user avatar
  • 43.9k
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
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, ...
Primus's user avatar
  • 65
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 ...
Casteurr's user avatar
  • 956
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 ...
Hanzyusuf's user avatar
  • 379
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
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 ...
Alex's user avatar
  • 43
4 votes
1 answer
4k views

How to vertically fill a JPanel with GridLayout or GridBagLayout?

I want to fill a JPanel whose layout is GridLayout, if it's not possible using GridLayout i would like to know if using GridBagLayout is possible and how? Here's the code: public class ...
Jonathan Solorzano's user avatar
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"); ...
Aravind Yarram's user avatar
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
4 votes
1 answer
2k views

android.support.v7.widget.GridLayoutManager$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParams

activitymain.xml <android.support.v7.widget.RecyclerView android:background="@color/primary_text" android:layout_marginStart="@dimen/...
Ankur Khandelwal's user avatar
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 ...
dwat's user avatar
  • 322
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 ...
Siddhu's user avatar
  • 1,228
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 ...
Paul Reiners's user avatar
  • 7,706
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?
Hanna's user avatar
  • 10.5k

1
2 3 4 5
13