jpanel

Disposing JFrame by clicking from an inner JPanel

天大地大妈咪最大 提交于 2019-12-18 09:33:48
问题 I'm trying to dispose my JFrame by clicking a button, located on a JPanel that is placed on the JFrame that I want to close. I tried to make a static method on the JFrame class, but ofcourse my IDE told me that wasn't going to happen. Anyone thinking of a solution? Thanks! 回答1: Try this: public class DisposeJFrame extends JFrame{ JPanel panel = new JPanel(); JButton button = new JButton("Dispose JFrame"); public DisposeJFrame(){ super(); setTitle("Hi"); panel.add(button); add(panel); pack();

Java - repainting JPanel gives an error

蹲街弑〆低调 提交于 2019-12-18 09:21:27
问题 I'm a beginner in Java, and I'm trying to create an application that draws a rectangle where ever the cursor is located. I've already done everything, but I can't get the mouseMoved(MouseEvent) method to repaint the JPanel . Without the repaint, the rectangle is only drawn once and that's it. With the repaint, it compiles fine, but when I run it, every time the mouse is moved, I get this big " Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException " error. So, can anyone please

More than one JPanel in a Frame / having a brackground Image and another Layer with Components on the top

試著忘記壹切 提交于 2019-12-18 09:05:27
问题 I've got a JFrame with a JPanel in which there is a JLabel with an ImageIcon(). Everything's working perfectly, problem is i now want to add another JPanel with all the other stuff like buttons and so on to the JFrame. But it still shows the background Image on top and nothing with the second JPanel. Can someone help me? Here is an extract of my code: JFrame window = new JFrame("Http Download"); /* * Background Section */ JPanel panel1 = new JPanel(); JLabel lbl1 = new JLabel(); /* *

More than one JPanel in a Frame / having a brackground Image and another Layer with Components on the top

对着背影说爱祢 提交于 2019-12-18 09:04:08
问题 I've got a JFrame with a JPanel in which there is a JLabel with an ImageIcon(). Everything's working perfectly, problem is i now want to add another JPanel with all the other stuff like buttons and so on to the JFrame. But it still shows the background Image on top and nothing with the second JPanel. Can someone help me? Here is an extract of my code: JFrame window = new JFrame("Http Download"); /* * Background Section */ JPanel panel1 = new JPanel(); JLabel lbl1 = new JLabel(); /* *

How does one make a component in the .CENTER of a Borderlayout occupy all center space and resize with the app?

别来无恙 提交于 2019-12-18 08:54:39
问题 My app/JFrame, using Borderlayout, has a toolbar at the top or north, a statusbar at the bottom or south and a JPanel.JTabbedPane.JScrollPane.JTable in the center. The JPanel is always a fixed size which is roughly adjustable using the various set*Size() methods applied in various combinations to the various components. But it's always a fixed size and always has east and west gaps. The north and south components stay fixed height and resize horizontally as one would expect. Surely this is

Set background color in Java on a JPanel doesn't work

为君一笑 提交于 2019-12-18 08:49:23
问题 I am working on a "paint-like" application (a little drawing software) to familiarize with Java 2D components. Here is my problem: I have a JFrame whose ContentPane is an instance of a class inheriting from JPanel. I want to set the background color to white but it remains on its default color... The class name corresponding to ContentPane is Container. Here is a simplified code: public class Container extends JPanel { public Container() { super(); this.setBackground(Color.WHITE); } } The

How do I hide the current JPanel and show a new one with a button in Java?

◇◆丶佛笑我妖孽 提交于 2019-12-18 06:57:31
问题 I unfortunately have to use multiple windows in this program and I don't think CardLayout is going to work because I can't have any buttons constant between the different layouts. So I'm trying to code a button to hide the present JPanel (thePanel) and show a new one (thePlacebo). I'm trying to hide thePanel in an ActionListener like this: frame.getContentPane().remove(thePanel); I thought this would work, but it just freezes my program as soon as I hit the button. Here's a chunk of the code

IP camera with OpenCv in Java

放肆的年华 提交于 2019-12-18 05:56:30
问题 I am trying to get and display an video stream from a IP camera. I found some sample code here:http://answers.opencv.org/question/24012/reading-video-stream-from-ip-camera-in-opencv-java/ But it is not working for me. my code works when I use my internal webcam, but when I switch the camera to the IP, it does not work. I have no idea why. Can someone please help me? Here is my code: import java.awt.BorderLayout; import java.awt.Image; import java.awt.image.BufferedImage; import java.awt.image

JPanel removeAll doesn't get rid of previous components

左心房为你撑大大i 提交于 2019-12-18 05:44:46
问题 I have a swing application in which I display images in a JPanel. If the app is unable to produce the image I want to remove the previous one from the JPanel and replace it with a JTextField and message. I can add the text field , but it's drawn on top of the previous contents, which is itself a subclass of JPanel. Here's what I have: private void displayMessage(String message) { JTextField tf = new JTextField(message); cdPanel.removeAll(); cdPanel.add(tf, BorderLayout.NORTH);//tried lots of

JPanel removeAll doesn't get rid of previous components

守給你的承諾、 提交于 2019-12-18 05:44:20
问题 I have a swing application in which I display images in a JPanel. If the app is unable to produce the image I want to remove the previous one from the JPanel and replace it with a JTextField and message. I can add the text field , but it's drawn on top of the previous contents, which is itself a subclass of JPanel. Here's what I have: private void displayMessage(String message) { JTextField tf = new JTextField(message); cdPanel.removeAll(); cdPanel.add(tf, BorderLayout.NORTH);//tried lots of