FAQ Database Discussion Community


True Full Screen JFrame/Swing Application in Mac OSX

java,osx,swing,jframe,fullscreen
I'm working on application and I'm making the GUI with Swing. I would like my application to be fullscreen. I can easily set the size of the window however I have not been able to make the application truly fullscreen (IE With the apple menu bar and dock hidden). All...

How to Update JFrame Components?

java,swing,jframe,refresh,listener
Well, i have this code. import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.ImageIcon; import javax.swing.SwingConstants; import javax.swing.JProgressBar; import javax.swing.SwingUtilities; import java.awt.Font; import javax.swing.JSeparator; import javax.swing.JTextPane; import javax.swing.JButton; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; public class Menu { private JFrame frmFelps; /** * Launch the application. */ public static void main(String[] args) {...

JFrame isn't loading properly

java,swing,jframe,jbutton
I've made a Java Project with multiple classes, one's the Shell.java. That launches a GUI (that uses swing) with Buttons and Images that launch other classes with className.main(args); This works fine except with one button, but I've coded the part like all others... (code below): File morseFile = new File("c:\\temp\\morse.png");...

add different jcomponents to jframe in java

java,swing,jframe,paintcomponent,jcomponent
I want to draw some different JComponents in one JPanel. I create some JComponents with different paint methods. Then create the objects in the main and put them to the JFrame. My problem is, that only the last Object is painted in the Window. How can I put different JComponents...

Issue with JFrame focus when disabling JButton

java,jframe,focus,jbutton
I'm having a really strange issue with my Java Application. I'm using Netbeans, and so I have a frameview with a main panel that has some buttons to choose a serial port and connect to it. It also has a menu bar to open up a bunch of different frames....

How to close a JOptionPane message box when pressing the x button?

java,swing,jframe
I used a JOptionPane showMessageDiaglog to display a message with options, but whenever I decide to back off and click the red X button. It still performs an action as if I pressed the first option. How do I make it close on exit? here's how I wrote it: int...

errors when drawing a rectangle that is read from an ArrayList?

java,arraylist,graphics,jframe,jcomponent
I am new to this website so please forgive me if I have broken any rules. Iv'e been looking for a couple days and have not found an answer to this, please let me know if this has been answered before. I am creating a java program that can draw...

How can I get a score to increase if the user clicked a Jbutton?

java,swing,jframe,jbutton
How can I get a score to increase if the user clicked a Jbutton (All of them ), and decreased if he clicked a random place in the frame ? here's the code package projet; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; public class Letstry...

I added a rectangle to a shape Arraylist but the shape will not show up on the panel

java,arraylist,jframe,jpanel,graphics2d
import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.ArrayList; @SuppressWarnings("serial") public class GUI extends JFrame implements ActionListener, MouseListener { private boolean drawLine = false; private boolean drawRec = false; private boolean drawOval = false; private final JButton line; private final JButton oval; private final JButton rectangle; private final JPanel buttonPanel; public...

Coding Graphics and KeyListener in java

java,swing,jframe,paint,keylistener
I was wondering how to properly use the Graphics library and also the Keylistener in JAVA. Underneath is my code, i believe i have done something wrong because the Window is blank with no Oval. Please help me out! import java.awt.Color; import java.awt.Graphics; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import javax.swing.JFrame; public...

3 Jpanel in JFrame, my button is not visible

java,swing,jframe,jpanel
I have a JFrame with three JPanel objects. I have a problem with two of the panels. I can see in my frame, the panel JPanelProduit with object but for the panel, JPanelInformations and JPanelVentes, I see nothing. Where is my error? My Code package IHM; import javax.swing.*; import Donnees.Categories;...

Calling a JMenuBar from another class

java,swing,jframe,jmenubar
I have the following code for a GUI with a button on it and code for a JMenuBar. MenuBarTest.java import javax.swing.*; import java.awt.*; import java.awt.event.*; import MenuBar.*; public class MenuBarTest extends JFrame implements ActionListener { JFrame myMainWindow = new JFrame("This is my title"); JPanel firstPanel = new JPanel(); JButton btnTest...

Simple quiz not showing next answer

java,swing,jframe
I'm trying to make a "Simple" quiz in Java using a JFrame. Basically long story short... When the user clicks the "NEXT" button after question 2, it doesn't show the next question... How can I get the code to proceed to question 3? CODE import javax.swing.DefaultListModel; import javax.swing.JCheckBox; import javax.swing.JFrame;...

Java - Applet to Executable Jar Wrapping

java,swing,applet,jframe,jpanel
I have written a Java XML Parser as an Applet. It is looking and functioning well enough in this form. My Question, Is if I want to run this without a browser, how Would I properly wrap it to run as an executable? GUI.java -------------- import java.applet.*; import java.awt.*; import...

JFrame error actionperformed

java,swing,jframe,actionlistener,visibility
I want to set the visibility of frame 2 to false, but whenever I do that, I get an error. I read something about this and it said that I needed to make my method I private method, but I can't do that since my method is actionPerformed. Somebody got...

Convert JSpinner value to a new int

java,swing,jframe,jspinner
I am using WindowBuilder to create a GUI. I'm kinda new to JFrame and I have a problem: I added a JSpinner and I want to save the number that I put in my spinner to an int so I can use it later on. Can someone please help me?...

JFrame/JPanel refreshing and text fields

java,jframe,jpanel,refresh,textfield
I'm trying to switch between displaying different JPanels in BorderLayout.CENTER in a JFrame. The JPanels each contain a JTextField and a JTextPane. Calling revalidate() and repaint() on the JFrame, I get a very strange result: the first time I switch to secondPanel by clicking secondButton, everything works as expected. Then...

Can JFrames be put in a parent window?

java,swing,jframe,jinternalframe
I have a project which creates several JFrames and shows them as separate windows. This can be quite confusing, so I want to collect all these frames in a parent window. I am aware of the concept of JInternalFrame which would certainly work in principle, but the project is quite...

Java Game actionPerformed questions

java,jframe,jpanel
Hi everyone so recently i've made a game similar to doodle jump with a jumper/object jumping to the next platform on top and if you fall of you lose. So anyway my game all works but there is one problem, I've make it that if you press on the space...

Why doesn't my JFrame repaint when I set a new Synthetica theme?

java,swing,jframe,themes,synthetica
I just set my applications theme to Synthetica Alu Oxide but some reason the JFrame doesn't repaint but another Synthetica theme will repaint the JFrame. This is what mine looks like. http://i.imgur.com/SOBDTs4.png This is what its suppose to look like. http://www.jyloo.com/images/screenshots/syntheticaAluOxide/democenter2.png public MainPanel() { JFrame frame = new JFrame(); frame.setTitle("Asteria...

refresh JFrame Java without doing new JFrame

java,jframe,jlabel
I'm working on a game where you can upgrade your stats in a shop. When you buy something it should refresh the JLabel which shows your Coins Is there a way to do that without doing a new JFrame? public void actionPerformed(ActionEvent e) { user.setCoin(user.getCoin() - 5); user.setMaxJump(5); EpixController.getInstance().coinsUpdate(user, -5);...

Java actionPerformed questions

java,swing,jframe,jpanel,action
Hello everyone I am new to java programming and I begin to fell in love with making simple JPanel or JFrame games. But recently I'm starting to challenge myself on writing a more complicated game called "Doodle jump". As most of you may already heard of this game you are...

Add user input to JFrame [closed]

java,debugging,jframe,user,jtextfield
How can I make a JFrame have an option for user input, that can also detect a certain input and do something afterwards? Is it something along the lines of JTextField?

How to open a JFrame that was previously hidden from another class?

java,swing,jframe,instances
I have 2 frames and in the first one, I press a button to go to the other and then I hide the frame with: frame1.this.hide(); How can I set that frame visible without creating a new one? I know that I can make an instance to open a new...

How can I make this timer() work as I want?

java,swing,timer,colors,jframe
I am having a bit of trouble with the code before. It is doing what I want, but I can only call the method once, if I call it more than that it won't work, essentially it only works once. So right now this ballG is an object. It starts...

LWJGL Display crashing when implemented with Jframe and canvas

java,swing,opengl,jframe,lwjgl
I'm working on creating a 2D Java game with a lighting engine with OpenGL using LWJGL, but I've hit a wall when trying to link up keyboard inputs. The render loop works fine, but as soon as I tried to implement a JFrame/canvas and the getParent/KeyListener combo The application crashes...

JFrame wrong location with Ubuntu (Unity ?)

java,swing,ubuntu,jframe,location
It seems that there is a bug with Ubuntu (maybe only unity). The decoration of the JFrame is taken into account for getLocation() and getSize(), but not for setLocation() and setSize(). This leads to weird behaviour. For instance, if you use pack() after the frame is displayed and the dimensions...

Making a Simple RPG- Creating a new JFrame

java,swing,user-interface,jframe,window
I am making a 4-class RPG. It has Player class which allows us to move the player. It has Board class which is for the map in the game. There is a Battle class which is for the battle phase. RPG is the main class responsible for running the game....

Extending JFrame - how does “super” keyword work?

java,object,jframe,super
I've made a class that extends JFrame, and in my classes constructor, to set the title I can either use: super("title"); setTitle("title"); or just create a JFrame object i.e: JFrame f = new JFrame("title); How does the compiler differentiate from all of these to conclude the same thing? I know...

Opening frame that is under the JavaFX program category

eclipse,video,javafx,jframe,mp4
Most of program is using JFrames throughout the application for all the different windows that can appear. However, I have to play an instructional video for the user inside a JFrame. I couldn't find a way to do this, so I had to make a JavaFX program. Is there a...

adding JFrame background caused .JAR to be broken

java,jframe
I want to know what is the problem in my code that caused .JAR file to be broken? when I double click on jar file it doesn't open but it was fine before adding background image to JFrame. I created a class called Cube to draw cube and I want...

JButton does not change a field value

java,swing,jframe,jbutton,actionlistener
I am facing a strange problem with a simple JFrame application which has only one button in order to change a field value. When I try to debug my application, it works fine, but when I try to run it, it doesn't work and gets stuck in the while loop....

Accessing JComboBox data from separate JForm

java,swing,netbeans,jframe,jcombobox
I've spent a bit of time browsing Stack Overflow and the internet looking for the answer to my question, but I found all the answers hard to understand and I was quite unsure if any of them related to my problem, so I decided I needed help in the right...

How does the sizing of a JFrame actually work?

java,swing,jframe
I have no purpose for what I'm really doing, just trying things out with Java Swing. What I have right now are these three variables: int[] gridIterations = {10,10}; //how many JButtons are made each row/column int[] frameSize = {600,600}; //size of the JFrame int[] gridSize = {60,60}; //by gridSize,...

How do you make Java JLabel show on JFrame after JFrame content is removed, revalidated, and repainted?

java,swing,jframe,joptionpane
I am currently creating a program and I am trying to make a JLabel come onto the JFrame after it is cleared from "Yes" being pressed on a JOptionPane. Currently, I have not been able to get it to work.`ready = new JLabel("Are you ready?"); ready.setToolTipText("Are you ready to begin?");...

Swing wait()/notifyAll()

java,multithreading,swing,user-interface,jframe
I am developing a Java application where when a button in the GUI is pressed, the user can click anywhere on the screen to record the x and y coordinates where they clicked.This is done by putting an undecorated, partly transparent JFrame over the entire screen that listens for a...

JFrame setSize as screen size but minus titlebar

java,swing,jframe
I want to have JFrame with size that fits my screen perfectly. I used getScreenSize(); to get resolution of my computer and set it to JFrame's size. However i found that Jframe's size is actually bigger than my computer's resolution because of the titlebar. (which mean u will find bottom...

Why my program works on JFrame but not on JApplet?

java,eclipse,swing,jframe,japplet
I've got a project in Java (developped with Eclipse), in which I use some Swing components. At the start, I worked with JFrame : I created a new class herited from JPanel (PanelTr), added in it my JLabels, JTextField and JButton with an ActionListener on my button, and added an...

How do I pass a value JFrame to JFrame by click of a button in Java?

swing,jframe
I need to pass value from JFrame to another JFrame by click of button. I'm new to programming. I tried everything. I don't know how accomplish this. Here is my code - import javax.swing.JFrame; import javax.swing.JButton; import javax.swing.JTextField; import javax.swing.JLabel; import java.awt.FlowLayout; public class Demo{ private final JLabel showInput; private...

How to store and mark all mouse-clicked-point on an Image loaded in JPanel?

java,event-handling,jframe,jpanel,mouseevent
Up till now I have used the code given below to load image in a new new JFrame and coordinates of pixels of image are hard-coded in the code itself. However, I wish to do it dynamically i.e mark points clicked by mouse and store all the coordinates in an...

JTextPane adding large spaces every time i insertString

java,html,swing,jframe,jtextpane
Hey i'm making a chat application and was at first using a simple JTextPane for a basic, color supporting, chat view pane. I then wanted to add html link support to make them clickable by adding an HTML listener and setting the content type to text/html. The clickable links work...

Components won't show up on JFrame

java,swing,jframe
This question is a repeat, but the other answers have not fixed this error. The components I am putting into my JFrame aren't showing up. I have been working with JFrame for a while now and as far as I can tell I am making no mistakes. My Code: public...

Should be really simple, how do I make a jbutton show a jframe i have already created via the window builder in eclipse?

java,eclipse,swing,jframe
Not sure if I'm just using a visual basic approach, but I was under the impression i could use the window builder in eclipse to create my Jframes, then simply invoke them when the button/actionlistener is selected... Like: JButton btn_register = new JButton("Register"); btn_register.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0)...

Java Homework: setVisible import

java,swing,inheritance,jframe
I'm working on some java homework and am having difficulty understanding what I am doing wrong. In this step, I am required to determine which class inherited by the JFrame class declares the setVisible method, then import that class and modify the code in the main method so the frame...

JCheckBoxes not being disabled after I setEnable(false) them

java,swing,checkbox,jframe,enable-if
If have 30 checkboxes and I don't want more than 6 of them to be checked. I have an int keeping track of how many are checked. Each box has an item listener which calls a method to see what that int is at, and if it reaches 6, the...

Is it possible to get mouse inputs from JFrame?

java,swing,jframe,mouselistener
Good day! I have experimenting with Swing and AWT, and I stumbled upon java.swing.JFrame and java.awt.event.MouseListener. Based on the following code: Game.java (...) public Game() { frame = new JFrame(); ih = new IH(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(400, 400); (...) frame.add(this); frame.addMouseListener(ih); } IH.java import java.awt.event.MouseListener; import java.awt.event.MouseEvent; public class IH implements...

JLabel not showing in JFrame

java,swing,jframe,jlabel
I have searched this problem in stackoverflow,however, i couldn't resolve my problem. So I have a simple image that I assign to a JLabel and add that label in to JFrame but it doesn't appear. Any help? PS: If the image that I set is not same with the screen...

How to stop JOptionPane from disabling root frame

java,swing,jframe,joptionpane,modality
How do I show a JOptionPane without disabling any currently open frames? I have a JFrame with a Start and Stop button. At any point, I want the user to be able to press the 'Stop' button on the main frame, to stop a secondary Thread (which was started by...

JOptionPane cancel button doesn't work properly

java,swing,user-interface,jframe,joptionpane
I am working with JOptionPane. it works great when user clicks on the ok button, but when clicking on the cancel button and when closing the message as well, it displays the error message. private void findActionPerformed(java.awt.event.ActionEvent evt) { try { String num = JOptionPane.showInputDialog("Number to Search:"); int number =...

how do I filter what I entered in the JTextField and display the filtered result?

java,string,jframe,jtextfield,indexoutofboundsexception
package javaisnotbannana; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.*; import javax.swing.*; public class Javaisnotbannana{ public static void main(String[] args) { window(); } //////////////////////////////////////////////////// public static void window() { JFrame window= new JFrame(); JPanel jp = new JPanel(); JLabel jl = new JLabel(); JTextField jt = new JTextField(30); JButton jb = new...

JFrame: String changing back to null after the value is changed in the constructor

java,swing,netbeans,nullpointerexception,jframe
Just for clarification, i'm using JFrame Form in Netbeans. Ok so basically i'm trying to change the value of a public global String (PictureName) using the constructor, because i'm trying to take another value from another class, but when I try to use it in my JLabel's code, it appears...

How to get the parent container of a JWindow in Swing?

java,swing,jframe,jwindow
I have one JFrame and calling a JDialog from that frame while initializing. In the dialog have a JButton, when clicking on the button a new JWindow opens. Can I fix the position of window in the main frame? How to access the parent container (JFrame extended) from JWindow extended...

How to use paint method in a JPanel

java,swing,jframe,jbutton,paint
I am working on a slot machine in Java and so far I created a button that will randomly generate two pictures. My code compiles but when I run it, all the stuff I put in the paint method does not show up. Is there anything I am missing? Thanks...

JPanels will not show up in JFrame

java,swing,jframe,jpanel
I'm making a simple GUI calculator. Before I insert the guts, I'm trying to get the GUI down. The problem that I'm having is that my JPanels containing the keypad and display will not show up in the main JFrame for the program. What am I missing? Main: import javax.swing.*;...

why do i have to re-size JFrame to see the component [duplicate]

java,swing,jframe
This question already has an answer here: I have to resize my JFrame for the contents to show up. How can i fix that? 5 answers i have a small problem the component in the JFrame are not showing until i re-size the frame then all component are visible...

How to make a proper JFrame in Java Language?

java,eclipse,jframe
Hello community! I am very new to Java language and need help to make JFrame work. I believe that the code posted below is wrong as it terminates. I am using the text editor Eclipse. Please help as I cannot find what the problem is. Thanks! import javax.swing.JFrame; public...

Mechanisms of setText() in JTextArea?

java,swing,jframe,jtextarea,settext
I try to show some text in my JTextArea in runtime. But when I use a loop of setText to show text in order, it only show the text of the last loop Here is my code: private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { for (int i=0;i<10;i++) jTextArea1.setText("Example "+i); } I want...

JPanel size is not known on start

java,swing,jframe,jpanel
When I create a Board instance from my Square instance, I try to assign the size of the window to the integers x and y. I fail to do this because it seems like on start the size is 0. In the constructor in Board.java, x and y shouldn't be...

How to display an image on another image?

java,jframe,jpanel,jlabel,game-engine
I try to create a little game in java but I'm in trouble. When I draw a map, I'm not able to display the characters without overwrite the titlesets of the squares. My goal is to be able to display many pictures on the same square (like the titleset of...

Java GUI - JButton opens another frame from another class

java,swing,jframe,jbutton,actionlistener
i'm having trouble to get the 2nd frame to display the GUI Components. i've opened the frame using the JButton from the 1st frame. Here's the screen shot This is the first frame - ClientModule.java 2nd frame - ClientMenu.java Here's the codes i've tried ClientModule.java import java.net.*; import java.util.*; import...

printing a 2 pages of jframe in java

java,swing,printing,jframe
i would like to print a jframe that contain a lot of textfield and buttons that contain a data. i want to print this jframe by clicking a Print jbutton. i tried this code. protected void print() { PrinterJob job = PrinterJob.getPrinterJob(); if(job.printDialog()){ try { job.setPrintable(new Printable() { @Override public...

Can't Refresh a JFrame/JSsrollPane

java,jframe,jscrollpane
This code is used to get a specific data from an xml file that we entered in jtextfield, until it works well the first time like it's showed in the image, but the problem starts when we want to search for another data, I get the data (I've already tested...

Can't Get ImageIcon to Display

java,swing,graphics,jframe,imageicon
I've looked at a ton of other questions where people have similar issues to what I'm having here (most solutions found by simple mistakes) but I can't for the life of me figure out why my graphics won't display in my jframe. I'm pretty new to Java Graphics so I'd...

Converting JFrame to JPanel

java,swing,jframe,jpanel
I currently have written some Java Swing using a JFrame and it works fine. But now I need to use multiple screens and they are done using cardlayouts. So i need to convert my JFrame to JPanel. Currently I have this line for my JFrame mainFrame.getContentPane().add(c4Panel,BorderLayout.CENTER); But if I convert...

How to display images selected from a ComboBox

java,jframe
When I compile, I have a blank window. No elements are being added to the main frame. What am I missing? public class Gui extends JFrame { private JComboBox<String> box; private JLabel picture; private static String[] filename = {"pic1", "pic2.png" }; private Icon[] pics = { new ImageIcon(getClass().getResource(filename[0])), new ImageIcon(getClass().getResource(filename[1]))...

How to preserve background colors between Multiple JFrames

java,swing,colors,jframe
Within my program I have a method to change the frame colours. I also have a method to open a new Jframe which is used as a settings menu for the app. However the values set in the initial jframe will not carry over. How may I preserve the colours...

Can't get my panel to save as an image

java,swing,jframe,jpanel,bufferedimage
I made a simple paint program but there seem to be some problems. First off, when I run the program, the components don't show up until I drag my mouse over every single one. Secondly, the drawPanel image I create only saves the background of the panel and not the...

Adding MouseMotionListener to paddle (Java Pong Game)

java,jframe,mouselistener,pong
I searched the entire web trying to find a solution but in the end i just ended up being much more confused and frustrated. I am trying to get my paddle to move (paddle_y). Paddle does not need an x coordinate and it just has to move up and down...

Problems with detecting mouseClick in a JPanel and preventing circle from painting in JPanel

java,swing,jframe,jpanel
My current program lets the user move a circle around the JFrame and also change its color by pressing one of the colors presented in the JPanel at the bottom of the JFrame. My code: import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JButton; import javax.swing.border.Border; import javax.swing.BorderFactory; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import...

The method createGUI() is undefined for type JFrame

java,swing,types,jframe,undefined
I am trying to add a title to my JFrame so it reads "CBallMaze Ball Maze Application" but whenever I type that in when I am creating the JFrame, it gives me the error message in the title. This code runs fine if I don't try to add a title...

setVisible(true/false) error JFrame

java,swing,error-handling,jframe
So, I have a problem. I know what the problem is, but I don't know how to fix it. I'll give you the code. public void initialize2(){ txtWaaropGokken = new JTextField(); txtWaaropGokken.setFont(new Font("Tahoma", Font.BOLD, 13)); txtWaaropGokken.setHorizontalAlignment(SwingConstants.CENTER); txtWaaropGokken.setText("Waar wil je op gokken?"); txtWaaropGokken.setBounds(10, 11, 414, 32); frame.getContentPane().add(txtWaaropGokken); txtWaaropGokken.setColumns(10); txtWaaropGokken.setEditable(false); JButton ChansesSimples...

How to access a LinkedList inside of main from my Jframe button call

java,swing,user-interface,netbeans,jframe
:::::: UPDATE ::::: I tried updating my JFrame to take a LinkedList as an argument, it looks like... public userLogin(LinkedList<dataUser> ll) { initComponents(); } My main is now calling it by ... userLogin frame = new userLogin(userLL); frame.setVisible(true); Still not able to use the LinkedList userLL inside of my JFrame...

Multiple JFrame or JDialog

java,swing,jframe,jdialog
I'm developing an application with Swing and there is a situation that I couldn't decide to what to do. I need multiple pages but; Should I use multiple JFrame or JDialog or something else? What are the advantages of them? Is there specific way to choose? ...

Issue drawing rectangle in negative direction - Java

java,jframe,paintcomponent,jdialog
I'm having issues attempting to draw a rectangle in the negative direction from a point clicked on a screen. I have the following class that simulates a screen capture software like Gyazo: class DrawSquare extends JPanel implements MouseListener, MouseMotionListener { // Components public JDialog frame; public Rectangle rectangle; public BufferedImage...

JFrame class not working in Main

java,swing,jframe,extending
I'm trying to write a Java program that declares a JFrame class and creates an object of that class in the main. For the life of me I cannot get the JFrame title, JPanel, and JButtons to appear when I create the "MyButtons" object in the main. All I get...

JPanel help- Drawing rectangles

java,jframe,jpanel
I'm using Graphics for the first time but I have an issue where nothing is showing up besides the background (identified as Bcolor). I'm trying to make a grid with lines using fill(new Rectangle) method with color Lcolor. I ran the debugger, and there doesn't seem to be any syntax,...

How to detect user input in a JFrame? (Java)

java,swing,jframe,user-input,greenfoot
Before you tell me to Google it, I have done, obviously. And most of the other questions asking same or similar things to this is very specific to their code that I can't seem to figure out how to put it in mine. So, anyway, I'm trying to make a...

How do I make a counter in a JFrame under the buttons?

java,swing,jframe,layout-manager
I am trying to work on a little program just for fun, and I want it so when I click the pineapple button it adds a pineapple to a string of text that I want under the buttons, same for rock. So basically I need a counter for the rock...

Java - JTextField fills all frame

java,swing,jframe,jtextfield
I am trying to achieve a very simple task: To make a JTextField that doesn't fill all screen. Currently I see this possible only with setMaximumSize, is there any other way? Here's my code: JFrame window = new JFrame(); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); window.setSize(screenSize.width / 2, screenSize.height / 2);...

Same actionhandler, multiple buttons

java,swing,jframe
I'm using JFrame to create an application and I want to know how it's possible to set the same actionhandler to different buttons. In my application I got 8 buttons and once you click on them, they should all disappear. This ''disappearing thing'' happens for each button, but after that...

JFrame layout helping/guide,

java,swing,jframe,layout-manager,grid-layout
I am having trouble with the layout of my JFRAME the layout is extremely difficult to me because i have just started learning it. the layout I'm looking for is select data START DAY: "textField" Month: "textField" YEAR: "textField" END DATE DAY: "textField" Month: "textField" YEAR: "textField" like it is...

how to print 2D array in TextArea

java,jframe,jbutton,jtextarea
Hello guys I need some help I wanted to print 2D array into a JTextArea with the JButton. I have this method: public static void getMaze(){ for(int i = 0; i<rows; i++) for(int j = 0; j<columns; j++) array[i][j] = "[]"; array [i3][i4]="# "; array [i5][i6]="# "; array [i7][i8]="# ";...

JFrame not including certain variables

java,swing,methods,jframe
I am new to using JFrame. I have a JFrame class that is separate from the main class. I have been having trouble getting it to work, like separating it from the main class. I have an issue though where a constructor in my JFrame class is not used, and...

How to split JFrame to have console on one side

java,swing,console,jframe,jpanel
I am working on this project github.com/csharpest94/Patience-Game and currently using this as my screen handler: public class Window extends JFrame { private static final long serialVersionUID = 1L; private ThePanel canvas; /** * The constructor creates a Frame ready to display the cards */ public Window() { // Calls the...

Add to a variable when a JCheckBox is selected

java,jframe,jcheckbox
I need to write an application that allows the user to choose insurance options in JCheckBoxes. Upon selecting a JCheckBox, I want to add the value of that option to the "TotalPrice". I initialized the totalPrice to 0, but when I try to add to it in the "if" statements,...

How to fill a jframe table from an arraylist?

java,swing,arraylist,jtable,jframe
I have a jtable that I created using java GUI and I need to fill from an arraylist. I'm not familiar with java and I have no idea how to fill a jTable. I don't know if I need to use TableModel or just JTable table = new JTable(data, columnNames)....

Can't paint on JPanel after clearRect() and repaint()

java,swing,jframe,jpanel,paint
I have a program which lets the user paint. But when the user clicks the clear button which calls clearRect() and repaint() the user can no longer keep painting on the same panel. Another issue I am having is that when the user clicks the save or open button (which...

How to set rectangle bounds to the frame?

java,swing,jframe
Looks like I'm doing everything as in the instructions but the frame doesn't work. Even if I put the usual bounds it stays the same. What am I doing wrong? import java.awt.Rectangle; import javax.swing.JFrame; import javax.swing.JOptionPane; public class TranslateDemo { public static void main(String[] args) { // Construct a frame...

How to implement .png pics in a JFrame?

java,graphics,jframe,awt
What I want to do is making a window, a GUI, and putting an image in it. I watched a YT tutorial (https://www.youtube.com/watch?v=Ap20Qw77TzY) and copied everything similar but the Window I make has no image at all. I tried different file types like .jpg and different window sizes, matching he...

Java setBounds() method (JFrame)

java,swing,jframe,dimension,setbounds
Hi Im using the setBounds method to open a window whith a certain size. But the size that I pass in the argument is the size of the window including the bars of the frame. How can I set the dimensions only for the content?

JFrame Scroll bar and Canvas

java,canvas,jframe,scrollbar
I'm having trouble trying to add a horizontal scroll bar to a JFrame that has a canvas. I draw an images onto the canvas and sometimes these images over-run the screen so I want a scroll bar to enable the user to see them. Here is the key section in...

Is there a way that I can set objects to overlap and conform to a grid system? [closed]

java,swing,user-interface,jframe,absolutelayout
so I am making a basic framework for a card game application (ex. blackjack, 21, solitaire, caravan) and I need to be able to display card images in groups that overlap and I need a grid system so I can easily set up the places where the "piles" go depending...

How can i Create Color simulation with JFrame, JLabel, using setForeground?

java,swing,animation,colors,jframe
I really doubt this is the best way to do it, but this is what I am working with currently. I have these 3 JLabel objects in a JPanel. So 3 circles are in a JPanel at font 99. left to right the circles are colored R B G.The \u2022...

Why does the first panel added to a frame disappear?

java,swing,jframe,layout-manager,border-layout
Below is an example of adding two panels to a frame. Only one panel (the 2nd, red panel) appears. Why does the first panel disappear? import java.awt.*; import javax.swing.*; import javax.swing.border.EmptyBorder; public class DisappearingPanelInFrame { DisappearingPanelInFrame() { JFrame f = new JFrame(this.getClass().getSimpleName()); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); f.add(new ColoredPanel(Color.GREEN)); f.add(new ColoredPanel(Color.RED)); f.pack(); f.setVisible(true); }...

Window Close Listener And setDefaultCloseOperation

java,swing,jframe,default,windowlistener
I have a question about the relationship between swing window listener and default close operation. The question occurs when I am dealing with below scenario: I add a window listener (WindowAdapter is used for the listener) for a JFrame, and override the windowClosing function: if the user closes the window,...

Changing a label during ActionEvent

java,jframe,label,jlabel
I am trying to enable/disable a label when a button is pressed and i want to do this during the event and not after it. As you can see below, i try to enable/disable the two labels: lblKeyboard and lblGamepad. They end up running after the "RemoteControl.run();" is executed but...

How To Make A JFrame/JPanel “Modal” So No Input Will Continue Until The Window Is Closed Or Button Pushed?

java,swing,jframe,jpanel
I had another question here and it was suggested me to make the program "modal" in order to block the program from running to the next line and "pausing" the program when a popup happened. I have tried it, but I do not understand how it works 100%. Here's my...

Accessing an object created by a constructor

java,swing,jframe
I'm trying to learn some basic GUI implementation in Java. I have 2 classes, one which contains a constructor. This constructor creates a new JFrame object. I'm having trouble with working with this JFrame constructor - I want to change its size, and other operations, but can't figure out how...

JFrame popup not showing content [on hold]

java,swing,jframe,event-dispatch-thread
I have ClassA that does some processing and I want it to create a popup Jframe ClassB that shows some statistics that ClassA calculated. So I did something like this: public class MainMenu extends javax.swing.JFrame { public MainMenu() { initComponents(); } private void initComponents() { calculateButton = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);...

JFrame not updating before thread.sleep()

java,multithreading,swing,user-interface,jframe
I'm creating a board game using a GUI and JFrames/JPanels where you can play against the computer. I have a method called showPieces() which updates board GUI by changing the image icons on an array of buttons (which are laid out in a grid format). Once the icons have been...