jpanel

How do I switch panels inside a frame depending on a button action?

I have created an application that has a toolbar, menubar and content area. I have added the menu and toolbar to the application window, but I am stuck with displaying the panel in content area based on the button action (like add, display) which is clicked through the toolbar. Is this a right way to do this? Is there any better way to d...

Java Swing - how to show a panel on top of another panel?

I wish to have an internal (non window) dialog to ask for member input. I would like the dialog to be placed centrally on an existing JPanel. I have looked at layeredpanes and these seem unusable due to only having a single layout manager (or no layout manager) across all the panes. I guess I could try to override JLayeredPane and provi...

Detect Mouse Move Event On JPanel

I have a JPanel, which I would like to detect the following events (1) When the mouse move in (2) When the mouse move out The (1) is quick easy. (2) is a bit tricky. Currently, I have to register event at all the components around JPanel. If the neighbor around JPanel detected a mouse move in event, this also means that JPanel is havi...

Adding additional JPanels to a JPanel

Rather basic question here guys. Basically I have code like this: public SuperPanel() { setLayout(new BorderLayout()); add(panel1(), BorderLayout.NORTH); add(panel2(), BorderLayout.CENTER); add(panel3(), BorderLayout.SOUTH); } And that all works well and good. The problem is that I have another part I wish to add to t...

Remove unnessesary spaces from Swings Components

i have 3 JPanel, the first is the base panel and the other two are added to the first. I have realised that there is a lot of space that is not used, shown by the black color and the white color around components. How do you remove this space? ...

Stacking Jpanels on top of other

Hello this is my question; I have created 5 very similar panels that are suppuosed to be visible in the same area of a frane on at a time, What I mean is that when the app stars one of them (JPanel0) is visible and the other four are created but invisible and when i hit Button1, JPanel1 sets to visible and Jpanel0 goes invisible, same w...

(Java) Appearing/Disappearing JLabel in a JPanel only disappears on resize

I'm working in Java, and I have a JPanel in a JFrame. In that JPanel, among other things, I have a JLabel that I want to make appear and disappear at will. I've tried setting visibility to true/false, adding and removing it from the JFrame and JPanel, and, having looked online, I tried validate()ing and revalidate()ing ad infinitum. What...

Why is the class CanvasPane not included in the Java API?

** Why is the class CanvasPane not included in the Java API?. import javax.swing.*; import java.awt.*; import java.awt.geom.*; /** * Class Canvas - a class to allow for simple graphical * drawing on a canvas. * * @author Michael Kolling (mik) * @author Bruce Quig * * @version 2008.03....

how to center image when Jpanel resized

How can i center image when i resize jpanel in swing ? my initial state of the Jpanel that its fits the size of the image ( with pack() ) but now when i resize the Jpanel with my mouse i will like to maintain the image in the center of the Jpanel relative to the Jpanel size ...

How can I draw rulers in a JPanel?

I have a JPanel that contains an image. I want to draw rulers on the JPanel's borders. How can it be done or where should I look for some hints? ...

How to make Jpanel expand to the size of the JFrame?

The below code is from the book objects First With Java By Michale Kolling and David J Barnes and the following is an exercise (ex 5.49) from the book.The ex is : Improve your drawFrame method to adapt automatically to the current canvas's size.To do this you need to find out how to make use of an objectof class Dimension. In the follow...

Embedding a JPanel in a Frame

I created a Java application in NetBeans which consists of a bunch of components on a JPanel. I know want to embed this application on a frame which will be a completely separate application. I can't seem to be able to do this...any suggestions? ...

How do I start optimising my Java code? - CPU is at 100%

i have written an application, but for some reason it keeps peaking at 100%. I ran a profile r on a few of the classes and a report show that isReset() and isRunning() seems to be called alot of times. Do you see anything wrong please inform me. thanks Class 1 is the only class that uses the isReset() code so i hope this helps u guys in...

loop through JPanel

Hi there, In order to initialise all JTextfFields on a JPanlel when users click a "clear button" I need to loop through the JPanel (instead of setting all individual field to ""). Can someone please show me how to use a For Each loop in order to iterate thru the JPanel in search of JTextFields. Very much appreciated Dallag. ...

PaintComponent Takes a Long Time, Ties up the Swing Event Dispatch Thread

I've customized a JPanel that displays a large, complicated diagram. Depending on the size of the data, it can take a few minutes to render in paintComponent(). I'm looking for a strategy to: draw the component without tying up the event dispatch thread. draw something in the JPanel to let the user know the image is being rendered. pe...

Layering many JPanels and adding them on the fly

Hi all. I'm developing a sim game based on Theme Hospital, which is quite an old game. I've made lots of progress on the underlying workings, however now I am coming to the GUI elements, which I haven't done alot of before. I am still rather new to java. The effect I am trying to create is like shown here... http://www.tubechop.com/watc...

Set size of a Jframe in the Jpanel program?

In the JPanel program, I wrote this: String size = JOptionPane.showInputDialog("What frame length?"); int s = Integer.parseInt(size); and I use the s variable in the body of the code. The problem is, I need to use the variable to also set the size of JFrame, and I don't know how to transfer the variable to that program.. Could I set ...

Making a JPanel manually resizable

I have a JFrame with BorderLayout as the layout manager. In the south border, I have a JPanel, I want this JPanel's size to be adjustable by the user, i.e. the user can click on the edge of the border and drag it up to make it larger. Is there any way you know that I can do this? ...

Resizing JPanel to prepare for printing without removing it from its original position

In my program I frequently need to print various JComponents (generally JPanels) and I like them to be full-page. The way I do it now is by using the following code: g2d.scale(pf.getImageableWidth()/componentToPrint.getWidth(), pf.getImageableHeight()/componentToPrint.getHeight()); but this often stretches or otherwise deforms whatev...

Nested JPanel resizing problem.

I have two JPanels (let's call these Panel1 and Panel2). These panels are of the same width, but varying heights. I want to put these JPanels into one big JPanel (lets call it Panel0), and stack them on top of each other (I decided to set Panel0's layout as GridLayout(0,1)). The problem, is that both nested panels (panels 1 and 2) end...