jpanel

How do I remove component from JFrame that uses BorderLayout.

The container uses a BorderLayout. I have a JPanel that I added to the CENTER. However the JPanel doesn't have a variable name for it. I could do contents.remove(nameofPanel) But since I added it like this contents.add(new CustomJPanel(), BorderLayout.CENTER); Now I'm trying to remove the current CustomJPanel and add a new one. How d...

Display a jpg image on a JPanel

What would be the most appropriate image type to display a jpg image (loaded from a local folder) on a JPanel? Cheers. ...

JTabbedPane adding null components

Hi Everyone, Riddle me this: I have a JTabbedPane that has custom JPanels in it. When I try and access those JPanels, all I get back is null. I know that the panels have been added because on the UI I can see the tabs. I can also interact with the panels and switch between tabs. It doesn't matter how I add these JPanels, it always return...

Drawing over a JPanel and adding the JPanel to JFrame

I need to draw a graph over a JPanel by overriding the JPanel's paintComponent() method. While designing gui using netbeans when i drag/drop a JPanel over JFrame it generates code by creating a private variable, JPanel object. In such a case how can i override its method to draw over it... or else if i write code for a class by exten...

Convert JPanel to image

Is there a way to convert a JPanel (that has not yet been displayed) to a BufferedImage? thanks, Jeff ...

Scrollable JPanel

How to make a JPanel scrollable? I implemented the scrollable interface yet when adding it to the containing panel with tabbedPane.add("Editor", new JScrollPane(storeyEditor = new MNScrollablePanel())); nothing works Code: public class MNScrollablePanel extends JPanel implements Scrollable { public Dimension getPreferredScroll...

how to make java JPanel and graphics2d transparent?

Hi all, Well the title is quite self explanatory. I want to build two panels one on-top of each other in layers using java. I want the top layer to contain a JPanel which will contain a graphics2d object. I'd like both the JPanel and graphics2d to have transparent background (I still want the content drawn by the graphics2d visible). Do...

Java's setPreferredSize won't resize JPanel

Hi all, I am struggling ( ! ) with java GUI development. All these small things that make obvious sense just don't work. I'll explain what I am trying to do and where I am failing (this is quite frustrating): I've got this graphics2d object which resides inside a panel. Now this graphics draws an image, it can go on and draw forever. t...

Which components can be added in a JDesktopPane?

Hi everyone, I'm having some trouble designing an MDI Application with Swing. I have no trouble implementing the JDesktopPane & JInternalFrames, my question will be a little more specific. Here is my base container Frame in a glance: package applicationGUI; import javax.swing.JFrame; public class DesktopContainer extends JFrame{ /* F...

Isn't Swing's JPanel pretty much like AWT's Panel? The former's widget is not showing up

I'm changing a program from AWT to Swing, as proposed on the second chapter of Java Swing's book, and the panel just disappears when I do the change from Panel to JPanel. The same doesn't happen when I change from Button to JButton. It seems to be a bug, since it appears to be trivially simple to do so - just adding an extra J to the na...

In Java 1.6, why does adding a Jpanel to another JPanel using the default add() not display the added panel?

I have a JFrame with a JPanel on it. I want to add another JPanel which is a preconfigured component onto the Jpanel inside my JFrame. If I do this: subPanel.setLayout(new BorderLayout()); subPanel.add(preconfiguredPanel,BorderLayout.CENTER); my Panel will show. If I do this: subPanel.add(preconfiguredPanel); my JPan...

How to make JLabels start on the next line

JPanel pMeasure = new JPanel(); .... JLabel economy = new JLabel("Economy"); JLabel regularity = new JLabel("Regularity"); pMeasure.add(economy); pMeasure.add(regularity); ... When I run the code above I get this output: Economy Regularity How can I get this output, where each JLabel starts on a new line? Thanks Economy Regular...

JPanel doesnt display the drawing

I have problem displaying drawing on JPanel. I created three class which linked to each other as the following. I was wondering why this code, doesn't display my drawing. c.add(pDraw); pDraw.add(draw); 1) MAIN public class mainPage { public static void main(String[]args){ JFrame appFrame = new Frame(); appFrame.setVis...

Images and Panels

I'm having a problem adding a JPanel on top of an Image. This is what I'm trying to do: Image bgImage = loadImage(filename); JPanel jp = new JPanel(); jp.setBounds(100,100,100,100); jp.setOpaque(true); jp.setBackgroudColor(Color.red); bgImage.add(jp); After doing this, I only see the bgImage. I tried everything but I still can't sho...

Placing drawing on JPanel

My program have 3 classes. 1) main, 2) frame, 3) drawingBoard. The logic of my program is that, a new drawing will be displayed every times user click on New pattern button (and this working fine). 1st class - main method public class mainPage { public static void main(String[]args){ JFrame appFrame = new Frame(); appFra...

Why I got black background when I save file as JPG

I set the JPanel background color as white. However when I save it into JPG or other image format, the background are all in black. I have put this code TYPE_INT_ARGB but it doesnt work. How can I set the background to other color? e.g. blue, white etc. public void paintComponent(Graphics g) { int width = getWidth(); i...

Wrong packing of JFrame using JPanel in borderlayout

Hello there. I am writing a simple application in Java that does some particle simulation on a bunch of sheep (don't ask). For this I want a window with a JPanel for graphics (which will be resizable with a simple combobox that contains some standard resolutions) and some other elements like buttons to start and pause the simulation etc....

Unwanted border around JPanel

I'm creating a form with a JPanel inside it for some graphics and some buttons for controlling the thing. For some reason I have to specify the JPanel to be 10 px less wide and 30 px less high than the actual graphics I want to put inside it. What causes this problem? This is the code: public class Window { public Sheepness sheepness;...

Displaying jpg image on JPanel

How can I display jpg image which I stored in arraylist in JPanel? Im not able to display the jpg files in the JPanel. String[] pictureFile = {"A.jpg","B.jpg","C.jpg"}; List<String> picList1 = Arrays.asList(pictureFile); Collections.shuffle(picList1); ImageIcon icon = new ImageIcon("picList1.get(0)"); JLabel label1 = new JLabel(...

JApplet/JPanel not receiving KeyListener events!

Hello, I cannot get my JPanel within my JApplet to receive keyboard events. I CANNOT FATHOM why! Note that... Clicking the panel (with mouse) before typing makes no difference. This is by far the most common advice I see given on the Net. I have tried using the 'low-level' java.awt.KeyEventDispatcher interface. That makes no differen...