I have some experience with Java but I am new with Swing. I am trying to run a very simple example but I run into an annoying problem that I cannot solve. I am trying to open a white window and draw a blue rectangle. Somehow, the rectangle only shows up after I manually resize the window. I have tried
Tag: jframe
How do I make it so that the table is displayed inside the JFrame in Main?
I am currently making a program for my school project, it is a fast food order calculator, my problem is that I have to be able to display the table inside the JFrame in Main, if I add “frame.add(table);” inside Main, nothing happens. Any help would be appreciated, thank you! } Answer Add frame.add(JScrollPane(table)); Change frame.add(label); to frame.add(label, BorderLayout.NORTH); Move
JFrame ending in some time
Whenever I run my code it ends in a few seconds. Why? This is the Main file: This is the GameWin file: When I try to run this code it shows running and then the code ends with exit code 1 which is good, but it just ends without showing the window. Is there something wrong with my JRE or
JFrame.addMouseListener doesn’t register clicks
I am currently writing an application in java that needs to take in input from the user. I have tried many ways to implement the input but none of them work. I am rendering objects with the graphics interface if that helps. I have tried a couple of methods to implement mouse interaction: And However when I run the application
Why does paintComponent get called only on some JPanels?
I’m trying to add a background to different JPanels (henceforth they will be called Window). These Windows are classes I created and make them inherit JPanel. Then depending on the state of the program one Window is set as the content panel of the program’s JFrame. The problem comes when in some Windows the background gets set and in others
Buttons not showing up in JPanel
I’m having a ton of trouble figuring out why the buttons in this won’t show? They were showing up earlier today when I test ran the program but now I’ve been stuck for 2 hours trying to get the buttons to show up again. It’s also really weird because the panel is definitely showing up because the phrase “Welcome to
How do I get a variable collected from a JTextField and give it to a getter method?
Very new to using Java and spent hours looking for a solution, but I cannot find out how to get the input collected by a JTextField with a button and ActionListener then be used for a getter method that can receive idNum so I can use the input in another class. Answer I believe what you are trying to do
JFrame keeps application running even after closing
I have a class with only static methods and one of them opens a JOptionPane error message dialogue using a JFrame object as component. This is the class + method: The ErrorPopup method is used inside a JavaFX controller and other places, called like this: Problem is that the application’s process won’t close when I close the the program from
How to clear a JFrame?
I’m still a noob to Swing classes and I wanted to clear the screen after the user activates a button. I have used the following and it didn’t really do anything. Answer you should use it this way
How to make an app using swing that only uses 1 JFrame?
I am making an app or (something.exe). I want to make a class that will serve as my main frame. That is because I don’t want to create new frame for each class that I will make. I want my class MainMenu to have the Frame of MainFrame where I can put buttons and etc. Answer Make use of Model-view-controller