Problem with creating multiple checkboxes on a fly

I am trying to read all the file name from a specific folder and trying to create multiple checkbox in JFrame with the same name. So, if there are 5 files in the folder, application should show 5 checkboxes in the frame. Here is my code. JFrame frame

Java - Numbers game - Multiple ActionListener in the same class

I am only 6 - 7 weeks into learning Java, so I apologize in advance if my code is sloppy or terminology is off. I'm trying to create program that creates a random number and allows the user to guess until they get the correct number. It serves no rea

JPanel position on JFrame

I have a problem with JPanel location. I started the creating a small game... I created 2 panels in design (on a JFrame). All worked good and the panels were on the correct places. In my game I have to use 2 graphic tables so I use 2 panels and I add

Java: upgrade to a single window

So I have been coding Java for a few months now, and I have been using JOptionPane to display text and variables in my games. I want to upgrade to a single window like a normal game, but I want to only focus on simple buttons and text on the screen.

Gif does not play JFrame

Hello, I have a gif in a JFrame. It all works fine except the gif is frozen on the first time as though it is an jpeg or png. Also, the stackoverflow is telling me I need to add more details even though I have added all the details required in order

How to cut a container into a bufferedImage image?

Is there any implementation available in Java to get buffered images from a container Eg: consider a JScrollpane, I will set the buffered Image size as 100*100, if the size of the scroll pane is 1000*100, I should get 10 buffered images, each buffere

Access a non-static public object from another distinct class

I am trying to create my own Font Chooser class in another separate class from the file where I have my main class (a JFrame application), and I would like to access to the textArea object of the main JFrame, in order to modify its font properties, b

How can I change the jtextfield border after 5 seconds?

I try to change jtextfield border after 5 seconds. But doesnt work. My code: // Here vaildate a field and set border to red if (ApplicationNameField.getText().equals("")) { Border newBorder = BorderFactory.createLineBorder(Color.RED, 1); Applica

Java actionlistener on the button

import java.awt.*; public class TestButton { private Frame f; protected Button b; public TestButton() { f = new Frame("Test"); b = new Button("Press Me!"); b.setActionCommand("ButtonPressed"); } public void launchFrame() { b.

Java - how to create delays

I'm wondering how can I make a Java program delay parts of code to prevent spamming buttons/other things in the program. So let's just say I'm making a program that displays the amount of times a user has clicked a button. I would like there to be a

Change the JLabel background on the MouseRelease event

I am trying to write a Java program that when you click on a certain element in the JFrame, the background of a JLabel is changed. The function that the event handling method calls to change the background does not work when called from the event, ho

replace the old JButton with a new one

I've created an array of buttons: JButton bt[][]=new JButton[8][8]; And then I call a function called refreshBoard in the following way public void refreshBoard() { for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { bt[i][j] = new JButton()

Problems with adding images to JFrames

I have been trying to load imageicons into a jframe. I have no idea why this code doesn't work. I have tried using jpanels and jlabels, and also other ways of loading images, but those don't work either. I think because of this it has something to do

Why does not it draw the image?

What I'm trying to do is make it so when I run my application, it starts the thread and the image is shown for 3 seconds (3000ms), then the thread stops running. The path for the image is correct, the image file exists, and the thread itself runs; ho

handle multiple keypresses by ignoring the repeated key

I had asked this in the comments section of another question (> How do I handle simultaneous key presses in Java?), and was asked to make a new question altogether. My problem is that when I create an ArrayList of keypresses they are not removed fast

How to have a scrollable JTextPane?

I would like to have a JTextPane that have scroll bar, how can I do so ? Thanks.To insert a scroll bar on your new JTextPane, just use a JScrollPane: JTextPane txt = new JTextPane(); JScrollPane jsp = new JScrollPane(txt); JTextPane API: http://downl

How to center in a JTable cell a value?

How to center a value in JTable cell? I'm using Netbeans.You need to customize the renderer. To center the first column you can do: DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer(); centerRenderer.setHorizontalAlignment( JLabe

Click on the event on jTable -Java

This question already has an answer here: ActionListener on JLabel or JTable cell 2 answers I have created a table in java in Netbeans and filled it with some data. Now I want to show some detail in a text area corresponding to the particular column

Why does `jLabel1 = jLabel2` not change the displayed value?

I have two JLabels created and added one of them to my JFrame but when I assign the other one to the added one the JFrame doesn't update add(jLabel1); jLabel1 = jLabel2; how can I fix this?In this line: add(jLabel1); You're adding to the GUI the obje

image does not appear in the java frame

trying to learn windows programming in java, want to display a image to a frame.here is the problem code: public static void main(String[] args) throws IOException { JFrame frame = new JFrame("hello world"); frame.setDefaultCloseOperation(JFrame

How to make JTable click on unselected drag instead of select

If you have JTable set with table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION) and then you click drag on a row that is not already selected, it starts selecting multiple rows. We don't want that behavior. We want it so if you cli

JEditorPane is the last line

Using a JEditorPane, is there any way to tell if the caret is currently on the last line? I cannot find anything in the API or more importantly JTextComponent of which JEditorPane is derived. I need to find this out when the user uses the down arrow

Problem in the Java GUI

Before reading about my problem, first look at this GUI Diagram. There are three bars at the top as follows: one having buttons "pictorial view", "textual view" etc. second having buttons "processes", "organisation"