jpanel

How do I change JPanel inside a JFrame on the fly?

To put it simple, there's a simple java swing app that consists of JFrame with some components in it. One of the components is a JPanel that is meant to be replaced by another JPanel on user action. So, what's the correct way of doing such a thing? I've tried panel = new CustomJPanelWithComponentsOnIt(); parentFrameJPanelBelongsTo.pack...

JFileChooser embedded in a JPanel

EDIT: I've posted a clarification as an answer, see below for more details. I am writing a java program that needs a file open dialog. The file open dialog isn't difficult, I'm hoping to use a JFileChooser. My problem is that I would like to have a dual pane JFrame (consisting of 2 JPanels). The left panel would have a JList, and the...

How can I draw something on a jPanel that will not be repainted ?

How can I draw something in JPanel that will stay the same and not be repainted, I am doing a traffic simulation program and I want the road to be drawn once because It will not change. Thanks ...

Java Swing: how to add an image to a JPanel ?

I have a JPanel to which I'd like to add JPEG and PNG images that I generate on the fly. All the examples I've seen so far in the Swing Tutorials, specially in the Swing examples use ImageIcons. I'm generating these images as byte arrays, and they are usually larger than the common icon they use in the examples, at 640x480. Is there ...

How to access multiple JPanels inside JFrame?

I have a JFrame that contains a "display" JPanel with JTextField and a "control" JPanel with buttons that should access the contents of the display JPanel. I think my problem is related on how to use the observer pattern, which in principle I understand. You need to place listeners and update messages, but I don't have a clue where to pu...

Java GUI repaint() problem? [solved]

Hi, I have a JFrame. This JFrame contains a JButton. I click the JButton and 10 JTextFields are created. the problem: I cannot see them until "I force a repaint()" by resizing the window. Only then do I see the JTextFields created. CODE: JPanel points = new JPanel(); //Creating the JTextFields: for (int i=0; i<10; i++) { JTextFie...

Java get JPanel Components

I have a JPanel full of JTextFields... for (int i=0; i<maxPoints; i++) { JTextField textField = new JTextField(); points.add(textField); } How do I later get the JTextFields in that JPanel? Like if I want their values with TextField.getText(); Thanks ...

Automatically size JPanel inside JFrame

I have a JPanel subclass on which I add buutons, labels, tables, etc. To show on screen it I use JFrame: MainPanel mainPanel = new MainPanel(); //JPanel subclass JFrame mainFrame = new JFrame(); mainFrame.setTitle("main window title"); mainFrame.getContentPane().add(mainPanel); mainFrame.setLocation(100, 100); mainFrame.pack(); mainFra...

Java- How can you set a pane's background with an image?

I'm wondering if there is any way to set a JPanel's background to an image instead of just a colour. Thanks and I'm working on dr. java ...

JPanel in JFrame in NetBeans

I have created a Java application (project) in NetBeans, in which I have designed a JFrame with menu bar, and different JPanels. I want these JPanels to appear inside the JFrame on action of different menu items, so that whenever the menu items are clicked different JPanels should appear inside the JFrame. I have designed both JFrame & J...

Java Paint Method Doesn't Paint?

I'm working on a simple little swing component, and I'm tearing out my hair trying to figure out why my paint method isn't working. The idea behind this component is that it's a small JPanel with a label. The background (behind the label) is supposed to be white, with a colored rectangle on the left-hand side indicating the ratio of two...

Adding JTextField to a JPanel and showing them

I'm building a little app using Java and Swing in NetBeans. Using NetBeans design window, I created a JFrame with a JPanel inside. Now I want to dynamically add some jTextFields to the JPanel. I wrote something like that: Vector textFieldsVector = new Vector(); JTextField tf; int i = 0; while (i < 3) { tf = new JTextField(); te...

Difficulty removing all components from a Jpanel

G'day all, I am coding a main menu for a project. The menu displays properly. I have also set up ActionListeners for the three buttons on the menu. What I wish to do is reuse the JPanel for a new set of radio buttons when the user chooses "Start a New Game". However, coding ActionPerformed to remove the existing components from the...

winforms panels vs java swing panels

In java swing I can insert panels into panels and so on, and not have to build a brand new window for every view of my applicaiton, or mess around removing and adding controls. Theres a panel clas sin C# however I cant see any way of creating a 'panel form' or basically just a form in form designer thats a panel and its contents. How d...

Best way of subclassing a JPanel in Swing

I am currently trying to build an expanding panel in Swing (akin the WPF's Expander control) and I'd like to retain the usual methods for manipulating it (i. e. setLayout, add, etc.). Only they should be routed to an embedded panel (the one being shown or hidden). How would one do that? Overriding every method of JComponent and re-routi...

Refresh JPanel

I need to display different drawings on a JPanel. I have put the drawing files into an array, but when I changed it using a button, the JPanel only displays first drawing and doesn't change to the next drawing... I have called panel.revalidate(), but it doesnt work. This is the segment of the code that I used but not working. The JPan...

moving items in JPanel

I am working on a pong game and I am working on the mechanism to move the ball. If I add 1 to x the ball moves 1 pixel to the right, if i add 1 to y the ball moves 1 pixel to the bottom. What if I want to move the ball at a certain angle how can 1 calculate the coordinates. ...

Multiple java Applets handling

I'm creating a simple java game Applet that has multiple Panels, The main game Panel has 4 JButtons that lead to the rest of the Panels when they are clicked. when the program runs, the four Panels are initialized 1st inside the init(), and inside each Panel initialization, I made all the Jcomponents invisible but only the main applet. ...

JPanel flipping out, FlowLayout not working as intended

Hi, The other day this code was working. I changed some things and re-ran it and now it doesn't work as intended. Obviously something I changed altered the behaviour, but I have gone back and reverted all of those changes and it still doesn't work. Disregarding that bit of information (to start), why the hell does this code not place a ...

How to include custom panel with NetBeans GUI Builder?

I have written a class that extends JPanel. Is it possible to use this in the NetBeans GUI Builder and have it survive all of the automatic code generation? I have used the customised code option in the GUI builder to instantiate the object as the new class, but it seems like the declaration can't be changed from JPanel, so only method...