jframe

how to make jpanel in jframe visible

为君一笑 提交于 2019-12-13 03:46:44
问题 I try to write a menue for a little game in Java. I thought it would be a good idea to have a Window class (extending JFrame) and then put a JPanel in it for the different Screens (Menue, Game, GameOver etc) If I put the buttons and stuff directly in the JFrame everything is shwown correct, but when I try to put a JPanel into the JFrame it doesn't work. Here is the code: public class Window extends JFrame{ private final int WIDTH = 800; private final int HEIGTH = 600; private final int

Autowiring not working in springboot application

泄露秘密 提交于 2019-12-13 03:43:34
问题 I am trying to create a Spring boot application with JFrame. I can see my beans in applicationContext but they are not getting autowired. I am unable to find the reason for this issue. Can someone help me with this? Here is the code: JavauiApplication - it is showing both userManager and userNameRepository is beans @SpringBootApplication public class JavauiApplication implements CommandLineRunner { @Autowired private ApplicationContext appContext; public static void main(String[] args) { new

Why does the second JFrame does not show components?

不问归期 提交于 2019-12-13 03:38:49
问题 I have the first JFrame and it works fine. When I push a button it is supposed to show a JProgressBar frame , but i get empty JFrame. I open it with p = new Progress("1/3"); p.setMax(2); p.setProgress(0, "Getting bytes..."); Anyone know why? EDIT: I am going to explain more detail(Because someone misunderstood and corrected my post in the wrong way) - On my main class i start the first JFrame: new Crypt(); And in the Crypt class i have registered a button ActionListener. OnClick it opens a

Java Open URL Inside of a JFrame

大城市里の小女人 提交于 2019-12-13 03:33:30
问题 I was wondering if there is a way to open a URL inside of a JFrame or JDialog. I need this to protect the URL. Is there a way to run a browser inside of a Java component such as a JFrame or a JDialog? 回答1: This should be what you are looking for, a web browser component that you can easily use in your SWING application 回答2: This would only make the URL secret for dummies. With a network sniffer like Ethereal, it would be trivial to know which requests are made by your application. Security

How do you reference a button inside of its actionlistener?

怎甘沉沦 提交于 2019-12-13 02:32:57
问题 I'm just starting to get used to listeners but I am still kind of new to working with them. I need to reference a button inside of its actionlistener to get the text of that button. my code I want is: for(int i = 0; i<48; ++i){ button[i] = new JButton(""); contentPane.add(button[i]); button[i].addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { x_marks_the_spot(); if(button[i].getText().equals("X")){ increase_hit(); } else{ increase_miss(); } } }); Obviously

How to intercept keyboard strokes going to Java Swing JTextField?

随声附和 提交于 2019-12-13 02:30:28
问题 The JTextField is a calculator display initialized to zero and it is bad form to display a decimal number with a leading 0 like 0123 or 00123. The numeric buttons (0..9) in a NetBeans Swing JFrame use append() [below] to drop the leading zeros, but the user may prefer the keyboard to a mouse, and non-numeric characters also need to be handled. private void append(String s) { if (newEntry) { newEntry = false; calcDisplay.setText(s); } else if (0 != Float.parseFloat(calcDisplay.getText()

Switching jPanels in Java from external class

六眼飞鱼酱① 提交于 2019-12-13 01:35:16
问题 I have jFrame class MainForm which contains main() , placePanel(panel) and drop down menu. From the items in drop down menu I call on placePanel(panel) method to place a specific panel in the jFrame container. This works fine. But, I don't know how to switch panels when I click on a button which is inside a jPanel class. When I try to call jFrame 's MainForm.placePanel(panel) from any jPanel which is loaded into jFrame 's container, I get the error: cannot reference non-static content etc. I

Repeat SwingWorker

落爺英雄遲暮 提交于 2019-12-13 01:29:09
问题 I want to build a JFrame able to run a background task every time a JButton was clicked.currently i am using a swing worker and it wont allow the task to be executed more than once. How can I enable repetition task for SwingWorker with JButton click. public class ScanFileFrame extends JFrame{ JButton btnTicking; JLabel label1; ScanFileFrame(){ JFrame jframe = new JFrame(); jframe.setLayout(new FlowLayout()); btnTicking = new JButton("Start Scanning Files"); label1 = new JLabel("No File

JPanel is not shown after adding it to JFrame

大兔子大兔子 提交于 2019-12-13 01:23:55
问题 I have to setup a basic JAVA application including a GUI based on swing. My idea was to create one JFrame and different JPanels and based on the users input to change the shown JPanel. After running my application the JFrame is shown but not the content of the JPanel. I thought up to here it should be strait forward... but as it seems it isn't. Hope you can give me a hint :) Here is my main: public class Client { public static void main(String[] args) { MainWindow window = new MainWindow();

JLabel text being cut off

喜你入骨 提交于 2019-12-13 01:19:03
问题 As you can see from the image above some of the text is being cut off :( Code: package malgm.school.clockui.ui; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.IOException; import javax.swing.*; import malgm.school.clockui.ClockUI; import malgm.school.clockui.ResourceLoader; public class ClockFrame extends JFrame { private static final long serialVersionUID = 1L; public final static int FRAME_WIDTH = 600; public final static int FRAME