jframe

JLabel only shows if initComponents() is deleted

蓝咒 提交于 2019-12-02 20:04:31
问题 MainFrame.java -JFrame public MainFrame() { initComponents(); Letters pl = new Letters(this); this.setContentPane(pl); this.setTitle("Preset Lessons"); this.pack(); } Letters.java -JPanel public Letters(JFrame frame) { initComponents(); JLabel label = new JLabel(); label.setText("Sample"); this.add(label); } if initComponents() in Letters.java is deleted thats the only time the JLabel will show up. How can I put the new JLabel to my existing JPanel? Contents of Letters.java's initComponents()

What's Wrong WIth My Code involving JFrames

一笑奈何 提交于 2019-12-02 19:44:08
问题 It's Giving me an error saying that "The method setContentPane(Container) in the type JFrame is not applicable for the arguments (GamePanel)" Here is my Code: package main; import javax.swing.JFrame; public class Game { public static void main(String[] args){ JFrame window = new JFrame("Dragon Tales"); window.setContentPane(new GamePanel()); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.setResizable(false); } } I am following a tutorial exactly and his screen shows no errors

How to properly refresh image in JFrame?

假装没事ソ 提交于 2019-12-02 19:34:29
问题 This is a problem that disturbs me for few hours now and I'm not able to find a solution by myself... I've found similar topics all around the net, but I couldn't find exact same problem with well explained and as simple as possible solution. I've also looked at EDT and SwingWorker API docs, but it was far too complicated for me :( So, let's get to the point. I have a simple JFrame with JLabel inside, that consist of my image: private static class MyJLabel extends JLabel { private ImageIcon

Java GUI Swing Model Explanation

吃可爱长大的小学妹 提交于 2019-12-02 19:26:26
I've been working with Swing for a while now but the whole model/structure of JFrame s, paint() , super , etc is all murky in my mind. I need a clear explanation or link that will explain how the whole GUI system is organized. OscarRyz The same happened to me. Actually to this day I don't quite get 100% how all it works. Swing is a very flexible framework - perhaps too flexible. With flexibility comes a lot of abstraction and with abstraction comes confusion. :) I've found the following articles worth reading. They helped me to better understand the big picture of Swing. A Swing Architecture

The method … is undefined for type JFrame

房东的猫 提交于 2019-12-02 19:14:44
问题 I'm trying to make a gui with two menu lists, with 3 items in each. What my problem is, is that when I click on an item, I get an error "The method displayList(int, AirplaneList) is undefined for the type JFrame" Code for AirplaneController.java: import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JFrame; import javax.swing.JOptionPane; import java.util.StringTokenizer; public class AirplaneController implements ActionListener{ public static

Is there a way to make JTextField for my address bar larger and curvier

孤人 提交于 2019-12-02 19:07:54
问题 I'm making a browser just to practice my Java skills, is there a way to make my address bar which is a JTextField, larger instead of the swing's default value and also curvier. Here's my code. //imports of the GUI //import java.awt.*; //import java.awt.event.*; //import javax.swing.*; //import javax.swing.event.*; //import javax.swing.text.*; //import javax.swing.GroupLayout.*; //extends is to use the GUI class public class ReadFile extends JFrame { private JTextField addressBar; //to have

Images In JFrame are overwriting each other not displaying both images over eachother [duplicate]

Deadly 提交于 2019-12-02 18:33:03
问题 This question already has answers here : Why does the first panel added to a frame disappear? (2 answers) Closed 3 years ago . public class Board extends JFrame { public void bd() { JFrame frame=new JFrame(); JLabel background1 = new JLabel(new ImageIcon("background.png")); JLabel knight=new JLabel(new ImageIcon("knight.jpg")); frame.add(background1); frame.add(knight); frame.pack(); frame.setResizable(false); frame.setVisible(true); } } I've been having some trouble with my code when i add

Calling a method from a JButton is freezing a JFrame?

帅比萌擦擦* 提交于 2019-12-02 18:21:10
问题 I'm doing a basic Pong game for a class. I have the Pong working, and I have a GUI display on startup, unfortunately I can't seem to start the game from the start JButton. I've commented where the problem is on the code, and removed irrelevant code. frame.add(GUIPanel); JButton startButton = new JButton("Start!"); GUIPanel.add(startButton, BorderLayout.CENTER); startButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { frame.getContentPane().remove

How to update Java Jframe controls from no-gui class on real time

半城伤御伤魂 提交于 2019-12-02 18:15:31
问题 I have a tedious problem with my Java JFrame project. What I want to do (and looking for how to) is add elements to my ListBox from a no-GUI class in REAL TIME, or in other words "asynchronous", with out freezing my app. Is this clear? I tried SwingWorker and Threads but without results. All I can do is update the listbox after all process finish (obviously with my app froze because my process is long). This is my architecture: And here is my code (not functional, just for understanding)

Create a form with a background Image (JLayeredPane)

牧云@^-^@ 提交于 2019-12-02 18:11:54
问题 I've been struggling to do something I guess pretty simple : I want to create a form (JTextField) with a background image. In order for the form not to cover the background Image, I'm using a JLayeredPane. I've been trying different stuff, nothing seems to work : for some reason, I'm either displaying only the background, or only the JTextField, but never both. My goal would be to have a background image that never changes, and just use my buttons / textfields on top of it. package gestion;