swing

JAVA - JFrame not looking proper when called from action listener

旧城冷巷雨未停 提交于 2021-02-11 12:19:01
问题 I have a problem with one of my frames not looking as it should, when it is called upon the press of a button. The frame looks as if it was rendered improperly, the label text in it is shortened, however when i move the same line of code outside the action listener, it works as it should. I have a sort of main menu, with two buttons, only the Generate Menu works at the moment, it looks like this: https://i.imgur.com/k1Ne5v9.png The code for the action listener: runMenuButt.addActionListener

How to slow down a for-loop? [duplicate]

允我心安 提交于 2021-02-11 12:17:42
问题 This question already has answers here : Is it possible to create a pause in the middle of Swing application? (2 answers) How can I pause/sleep/wait in a java swing app? (1 answer) Closed 4 months ago . I am creating an app that finds the shortest path in a maze, using JavaSwing. I have a two-dimensional matrix, both logical and graphical, made up of JLabel's, which I can use to paint paths and walls. So far I have this: As you can see, the start node moved from a position to another position

How to slow down a for-loop? [duplicate]

余生长醉 提交于 2021-02-11 12:17:18
问题 This question already has answers here : Is it possible to create a pause in the middle of Swing application? (2 answers) How can I pause/sleep/wait in a java swing app? (1 answer) Closed 4 months ago . I am creating an app that finds the shortest path in a maze, using JavaSwing. I have a two-dimensional matrix, both logical and graphical, made up of JLabel's, which I can use to paint paths and walls. So far I have this: As you can see, the start node moved from a position to another position

How to get string from JTextField and save it in variable?

泄露秘密 提交于 2021-02-11 10:39:29
问题 I am making a simple kid game that will ask the user to enter his/her name in a JTextField and that name will shown in other class after ending the game. I made new object and used it to call the method getName but when I call the method it return null I want it to return the name that the user entered. This is the code: package learn_englishTest; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import java.awt.Dimension; import java.awt.Font; import java.awt

Save only if multiple JTextFields are not empty

与世无争的帅哥 提交于 2021-02-11 07:21:07
问题 I have multiple JTextField s and JComboBox in my JFrame . So whenever I click the _Add_ button it will check if the four (4) text fields in Current Medication Panel is Empty. If it is not then Execute, but it also depends if the Personal info Panel text fields are filled. But I have a problem when I use the if and else statement, if I use the if and else : if(condition if the first textfield is empty) { // execute something like the textfield turn to red } else if(condition if the second

Swing: How to reduce the response time of MouseInputAdapter?

泄露秘密 提交于 2021-02-11 06:59:40
问题 I've made a tool which could allow user to draw on screenshot.Here is my code: package GUI.Views; import javax.swing.*; import javax.swing.event.MouseInputAdapter; import java.awt.*; import java.awt.event.MouseEvent; import java.awt.image.BufferedImage; public class Canvas extends JPanel { public static int radius = 5; public class DrawPointListener extends MouseInputAdapter{ private void draw(Point p, int radius){ Graphics2D g2 = (Graphics2D)getGraphics(); int x = (int)p.getX() - radius/2;

Can you add JButtons inside a JPanel

拟墨画扇 提交于 2021-02-11 06:16:06
问题 I'm making a Battleship game using one board. The picture below shows how the board GUI should look. My current code sets up a board without the 'menu-layer'. (see picture) I tried doing this using Swing GUI designer in Intellij and got the following form (see picture), but can't find a way to insert these buttons inside the panel. Currently, I have got the following code. package BattleshipGUI; import javax.swing.*; import java.awt.*; import java.awt.event.*; public class BoardFrame extends

JOptionPane#showMessageDialog(…) does not block on the EDT

五迷三道 提交于 2021-02-11 04:30:36
问题 Upon reading this question, I decided to execute the code that displays a message dialog in my application on the Event Dispatch Thread (EDT). To do this, I modified my method that shows a message dialog from: private static void showMessage(final Component parent, final String message, final String title, final int type) { System.out.println("Before dialog."); JOptionPane.showMessageDialog(parent, message, title, type); System.out.println("After dialog."); } to: private static void

JOptionPane#showMessageDialog(…) does not block on the EDT

大兔子大兔子 提交于 2021-02-11 04:25:22
问题 Upon reading this question, I decided to execute the code that displays a message dialog in my application on the Event Dispatch Thread (EDT). To do this, I modified my method that shows a message dialog from: private static void showMessage(final Component parent, final String message, final String title, final int type) { System.out.println("Before dialog."); JOptionPane.showMessageDialog(parent, message, title, type); System.out.println("After dialog."); } to: private static void

JButton showing up in the wrong spot after repaint is called

不问归期 提交于 2021-02-10 20:21:33
问题 I am trying to add a couple of JButton objects to my GUI program in Java and it is adding them to the JPanel (which is the main file of the program) but it is appearing in the incorrect spot. It is showing op at point [0, 0] and the action that is linked to it is happening at the correct spot. The rest of the elements on the panel are Images so the repaint method is called very often. private void init() { setLayout(null); setBackground(new Color(r, g, b)); addMouseListener(this);