All Questions
Tagged with grid-layout jbutton
48
questions
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 ...
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
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 ...
2
votes
2
answers
2k
views
Accessing locally defined JButtons in a GridLayout JPanel
Lets say you have a GridLayout of JButtons in an NxN grid, in code such as this:
JPanel bPanel = new JPanel();
bPanel.setLayout(new GridLayout(N, N, 10, 10));
for (int row = 0; row < N; row++)...
2
votes
2
answers
1k
views
How to remove excess space at bottom
I'm creating a simple Java Swing application. The build set up is a Grid Layout of 3 rows and 1 column. Inside the top row is another Grid Layout that has two columns, and inside each of those columns ...
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 ...
2
votes
1
answer
6k
views
Grid Layout implementing Specific Buttons ActionListener
I'm having trouble; I'm trying to implement a cinema booking system however I cannot set an actionListener to a specific button on different grids. The way I want it to work is each user will have a ...
2
votes
1
answer
307
views
On Screen Keyboard gui is not working
I am making a trying to display a textarea at the top and Keyboard keys below it, but when I run this code, the whole thing is mixed. What am I doing wrong and how can I solve it? Here is the code:
...
2
votes
1
answer
1k
views
How do I select specific cells into a Java grid GUI?
I'm developing a GUI grid and I need to select specific cells. I used JFrame. My goal is to fulfill the first column and the last row with numbers, like x-y axes.
I have tried to declare an array of ...
1
vote
2
answers
164
views
Java - Unusual GridLayout behaviour
Just playing around with Swing and wondering why the following code constructs a layout that seems to have three columns when the GridLayout is defined as 10 rows and 10 columns?
Can anybody explain ...
1
vote
2
answers
398
views
Grid layout not working?
I am trying to make a 2x2 grid layout that has a JLabel on the top left, and three buttons on the other three spaces. When I do this, I get the unexpected result of one big button (filling up the ...
1
vote
2
answers
234
views
JButton and its Location methods acting very weird
my problem is, that when I create a JButton, whithin its constructor, I set its location to some relative coordinates, say x = 5, and y = 6, using the following code:
this.setLocation(new Point(x, y))...
1
vote
2
answers
303
views
How should a JButton keep track of its position in a GridLayout?
I have a class called cell, which extends JButton. Then I have 16 Jbuttons in a gridlayout(4,4,3,3). Is it possible to have every cell keep track of its position in the gridlayout(I will need to know ...
1
vote
1
answer
663
views
Adding an array of text buttons to a grid lay out
I am not sure exactly what I am doing wrong here, I want to create a grid lay out
using a Jbutton array, however it is giving me a " null Pointer exception ". Can't
seem to find exactly how to ...
1
vote
2
answers
3k
views
How do I keep a JButton from changing size?
I'm trying to make a simple game where you can set out tiles that make up a celtic design and I can't seem to make the buttons stay the same size. Here's the code:
public class CTGContent {
...
1
vote
2
answers
6k
views
How to get components from a JFrame with a GridLayout?
I have a question about Java and JFrame in particular. Let's say I have a JFrame that I am using with a GridLayout. Supposing that I have added JButtons in the JFrame, how can I gain access to the one ...
1
vote
1
answer
3k
views
Grid Layout Java
I have created a java program that shows a grid of buttons and labels and i want to know how to pit a constraint on the labels and buttons so they dont re-size when window is dragged out.. can anyone ...
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 ...
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....
1
vote
1
answer
688
views
Setting layout of my menu object
I cannot set my new windows layout. I have a menu and submenus. I have an action listener on my submenu which directs me to new window. The problem is I cannot set it to given layout. Here's my code:
...
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 ...
1
vote
1
answer
2k
views
Beginner: JButton/Gridlayout (Similar to Minesweeper)
I am a beginner with Java and eventually I would like to create code for a robot I am making for a senior project. I am planning for the robot to set up dominoes in a specified pattern to then be ...
0
votes
3
answers
2k
views
In Grid Layout the Jbutton size is not changing with the use of setBounds() in java
While making a frame using GridLayout the button size is not changing using setBound(). The code for the frame is :
f1=new JFrame("Select any one");
ch=new JCheckBox("SUBSTITUTION CYPHER")...
0
votes
1
answer
284
views
A Grid of Panels that are made of buttons
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Game extends JFrame implements ActionListener {
private JPanel panel;
private JButton[] button;
private int count = 0;
...
0
votes
2
answers
2k
views
JButtons on GridLayout - MineSweeper
I'm writing MineSweeper and using JButtons on a GridLayout. The numbers of rows and columns are entered by the user, so setting fixed size may cause several problems.
How can I remove the space ...
0
votes
1
answer
39
views
How can I set the dimension of some particular JButton component (in this case btnPlus)?
I tried to use setSize() but didn't work. then I also used setPreferredSize(new Dimension(x,y)). Yes it does work but it changes the size of all the Components in that (oPanel) Panel. I just want to ...
0
votes
1
answer
145
views
How do I change button labels in a grid?
I'm trying to make a game which involves moving pieces by dragging and dropping them from square to square. However, I'm trying to do so using buttons with labels (as an exercise). So, for instance, a ...
0
votes
3
answers
94
views
Java keeps giving me my coordinates multiplied by 93
When I set X and Y values for my array of JButtons, I get back the correct values only multiplied by 93. I can solve the problem by dividing the value by 93 but I would rather find out where the bug ...
0
votes
2
answers
252
views
How to create dynamically JButton value in DesignGridLayout library?
i create grid layout using DesignGridLayout java library (here).
in the sampe if create 3 column layout. using this code :
layout.row().add(new JButton("Button 1")).add(new JButton("Button 2")).add(...
0
votes
1
answer
85
views
Why is my JButton size not changing with either setSize() or setPreferredSize()?
I am making a basic calculator for a school project, and one of the requirements I need to meet is to change the size of a JButton inside of a JPanel. I have tried to do this, but it doesn't change.
I ...
0
votes
1
answer
298
views
Java JFrame button organization
How do i create a jframe that organizes the text box and jbuttons, with the textbox on top and a 3 by 4 grid layout of buttons 1-10?
"TEXT BOX HERE"
[1][2][3]
[4][5][6]
[7][8][9]
[(][0][)]
This is ...
0
votes
1
answer
49
views
GridLayout do not add a component by button click?
While adding JButton components at program start, it won't work when trying to add some button later through e.g. a button click.
Perhaps just a syntax problem.
What could be the cause?
The example ...
0
votes
1
answer
996
views
Adding Grid of Buttons to JPanel
I'm trying to make a grid of 20px x 20px buttons that I define as "cells", blank by default, no special decorations such as shading, and change color when clicked. (They are meant to show "1" just for ...
0
votes
1
answer
6k
views
jbutton setVisible(false) setting back to setVisible(true) not working
I have a code that when I click the jButton it should set to not visible and the other JButton which is already set to FALSE should be TRUE, the setVisible(true) is not working.
buttonGrid[row][col] =...
0
votes
1
answer
77
views
Remove JButton using method of KeyListner Interface
I used ArrayList to put buttons into JFrame,
and now I want to make a program which removes the JButton with pressing specific key.
However, when I press the key, the button on the frame doesn't get ...
0
votes
1
answer
1k
views
Changing JButton text in GridLayout on ActionPerformed
I am trying to change JButton text when clicked. Buttons are in array in GridLayout. I tried to use .setText, but NetBeans displays an error.
local variables referenced from an inner class must be ...
0
votes
1
answer
1k
views
Why is this not showing buttons in gridlayout?
Im trying to create the so called "15 game" , which is like a slide puzzle with 16 buttons, 15 of them with numbers 1-15 and a empty one. Clicking on a button next to the empty one will switch ...
0
votes
2
answers
49
views
Is there a way to place JButtons with different spaces in the begining at the GridBagLayout?
I'm trying to do something like this:
But I can't leave spaces before the buttons. I have tried to add invisible buttons, but nothing has changed.
for (int i = 0; i < gameSize; i++ ){
c....
0
votes
1
answer
57
views
Buttons dont add to Jframe
I can't create a field with this code.
I want to load a file and the field should add arrays for the specific size. The problem is that the buttons are not shown in the frame.
Does anyone have an ...
0
votes
1
answer
444
views
Cards shuffle in gridlayout when I Click on a button in the grid
This is my first time using this site so don't go hard on me
I'm trying to make my own card game and in the game, the cards are placed in a 6 x 9 gridlayout. Everything else I can handle, but there ...
0
votes
1
answer
263
views
gridLayout of JButtons, actionListener for each JButton
I have a gridLayout of JButtons. I'd like to distinguish every JButton from each other in the actionPerformed function.
I don't want to "name" each JButton. The user press a JButton randomly. Is ...
0
votes
1
answer
186
views
Create animation JButton Grid java
How can I do a similar drop down animation on gridlayout?
I'm trying to do the game Connect 4 with swing lib.
Why this doesn't work?
private class ButtonListener implements ActionListener {
...
0
votes
0
answers
131
views
Why do you jbuttons only align right when i resize the jframe
I'm having a problem with jbuttons inside a jlabel on the jframe.
I'm attempting to make a minesweeper-like game where i will need lots of jbuttons - in this case there's 225, i have the buttons ...
-1
votes
2
answers
1k
views
GridLayout not displaying correctly
I'm attempting to create an array of buttons and add them to a GridLayout, but for some reason, the grid does not get drawn correctly if I make it larger than about 5 by 5. If it's between about 7 by ...
-1
votes
1
answer
2k
views
FlowLayout / GridLayout combining?
Alright I am trying to create a program that takes System.in from a scanner, places the input in a string, then creates a button layout based on the input. I am pretty new with Java and somewhat self ...
-1
votes
1
answer
54
views
GridLayout not displaying JButtons
I currently have GridLayout(3,0) and I want to add some buttons. However, nothing shows up when I run my program.
Here is the code (the class extends JFrame):
public void initializeGraphics() {
...
-1
votes
1
answer
59
views
Java Swing, JButton not showing on a panel with a grid layout
I've been trying to add a grid layout of buttons onto a jpanel, but nothing shows up on the jpanel when I run the code.
public class MyFrame extends JFrame{
public static final int WIDTH = 800;
public ...
-3
votes
1
answer
187
views
Adjacent JButtons [closed]
I am creating a word game where letters must be chosen from a 6X6 grid. However, only adjacent letters can be chosen(ie. adjacent buttons). What way is there of identifying that buttons are adjacent ...