jframe

Image won't appear in JLabel

强颜欢笑 提交于 2019-12-11 02:53:28
问题 I've created GUI for my application using Netbeans' GUI Builder. I am trying to display a JFrame containing a JLabel with an image, and I can't get the Image to display. My generated code : private void initComponents() { //... jLabel1 = new JLabel(new ImageIcon(myPicture)); } And my class code: public class GUIWindow extends javax.swing.JFrame { BufferedImage myPicture; /** Creates new form GUIWindow */ public GUIWindow() throws IOException { myPicture = ImageIO.read(new File("images/logo

Drawing inside multiple JPanels

感情迁移 提交于 2019-12-11 02:38:12
问题 I have three JPanels inside a main Frame. Clockwise from the left, in the first panel I plan to have some controls which dictate the drawing on the panel 2. The third bottom panel will show some informations. What I understand is, I have to override paintComponent so that I can achieve the desired effect on the second panel. Right now I just want to test it, whether I can draw simple texts on this panel. But in fact, I am having problem to draw anything in any of the three panels. The code is

How to move move a rectangle in JFrame using KeyListener?

跟風遠走 提交于 2019-12-11 02:18:01
问题 I'm trying to get a rectangle in my JFrame to move when I press a given key on the keyboard, but I'm seemingly having a hard time doing that. Here's my code: package TestPackage; import java.awt.Color; import java.awt.Graphics; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import javax.swing.JFrame; import javax.swing.JComponent; public class Mainframe extends JComponent implements KeyListener { private static final long serialVersionUID = 1L; int x = 350; int y = 250;

Why Are My Buttons Taking Up The Whole JFrame?

醉酒当歌 提交于 2019-12-11 01:50:04
问题 My code was working before, but now one JButton takes up the entire JFrame, any help would be appreciated! I am using a FlowLayout called fl and a class called Ken I have ten buttons called (oneButton, twoButton, threeButton, etc..) MY CODE: import java.awt.ComponentOrientation; import java.awt.Dimension; import java.awt.FlowLayout; import javax.swing.JButton; import javax.swing.JFrame; public class Ken { public static void frame(){ JFrame frame = new JFrame("Pow"); frame.setSize(500, 600);

Java background JFrame with a Jpanel arranging images in a grid

◇◆丶佛笑我妖孽 提交于 2019-12-11 01:17:04
问题 so I've been working on my program and I am having trouble getting setting up a JFrame with a background image of a network map and then setting a JPanel using a MigLayout on top of the JFrame which will allow me to place images in accordance to the network map. I have seen several different ways on how to set a background image and have tried using an example I found elsewhere on this site but it's not quite working. Also, I researched more on this and found that having a JPanel ontop of a

How to add a JScrollPane onto a JTabbedPane using a null layout?

怎甘沉沦 提交于 2019-12-11 01:14:31
问题 I want to implement a Scrollbar onto my Tab. However nothing is showing and there are no exceptions. I think I need a: scrollPane.setViewportView(scrollPanel); But it didn't work as well. I am wondering when adding a Jscrollpane onto a JTab how do you set it visible without using an explicit frame. If I use a frame and add it on the frame it creates a new window. However how I got this program the Frame looks built I assume and this complicates everything. import java.awt.*; import javax

Resize JFrame to JPanels inside JLayeredPane

与世无争的帅哥 提交于 2019-12-11 00:59:39
问题 I'm working on a Swing GUI using the JLayeredPane . The JFrame has a JLayeredPane which contains two JPanel s. Later I want to display some components in the JPanel s, I cut this part of the code to make it shorter for you. How do I resize the JFrame to the sizes of the JPanel s? frame.pack() does not work and without the line setting the preferred size the GUI will show with minimal size. import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt

Java 7 resize a JFrame (my GUI): the componentListener is not getting fired

久未见 提交于 2019-12-11 00:47:51
问题 I've Googled around and could not find an answer: I have a JFrame as a GUI and set a componentListener like this.addComponentListener(new CL(this, logger)); In the componentListener I have the componentResized, etc... public void componentResized(ComponentEvent e) { if (e.getSource() == gui) { here I do the code } } Everything is working fine under Java 6, but under Java 7, the Jframe is being resized but is not being repainted: the component listener is not getting called I tried some

Painting on JFrame without extending

女生的网名这么多〃 提交于 2019-12-10 23:52:47
问题 My application is not JFrame-oriented, it just uses one for output. I just need to be able to tell it to draw a rectangle here, clear the screen now, a few hundred times. To do this, I wrote the following code in my main, which, by my understanding, should clear the entire JFrame to a nice blue background color. JFrame frame = new JFrame("Maze Master Premium Super-Deluxe V199.39"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); int resolution = 20; int frameWidth = horiz * resolution;

How do I save my JScrollPane position after I do a JFrame.pack()?

梦想与她 提交于 2019-12-10 21:46:43
问题 I have the following code: JFrame frame = new JFrame(); JScrollPane scrollPane = new JScrollPane(new panel(with stuff in it)); frame.getContentPane().add(scrollPane); So the user scrolls a bit and then clicks a link on my panel and then I do a pack(), so I try the following code: int val = scrollPane.getVerticalScrollBar().getValue(); frame.pack(); scrollPane.getVerticalScrollBar().setValue(val); But this code still returns my scrollBar back to the beginning instead of keeping the position it