Java >> adjusting boundries of JPanels in JPanel in JFrame

by Novice » Mon, 01 Dec 2003 05:37:30 GMT

Hi, I tried searching through the google groups, but am obviously using the
wrong search words.

I have a JFrame with a JPanel in it. The JPanel is using the following
layout:
new BoxLayout (parentPanel, BoxLayout.LINE_AXIS)

Then I added two JPanels to the parentPanel.

But then I would like to click and drag the separator between the two panels
to change the size of the two JPanels.

Any hints?

Thanks,
Novice



Java >> adjusting boundries of JPanels in JPanel in JFrame

by Alex Hunsley » Mon, 01 Dec 2003 21:51:46 GMT



Look at JSplitPane, it will do what you're looking for.

alex

Java >> adjusting boundries of JPanels in JPanel in JFrame

by Novice » Mon, 01 Dec 2003 22:23:41 GMT


[snip]

| Look at JSplitPane, it will do what you're looking for.
|
| alex
|

That is what I'm looking for - thanks.

Novice

Similar Threads

1. Custom JPanels inside another JPanel. - Java

2. Display multiple JPanels in one JFrame using Swing

Hi List,

I am hoping to get some advice on how to do this most efficiently.

I have a swing program wich has one JFrame "mainframe".  I also have
several JPanels each with JButtons, text and images on them.


When the program starts I put a blank JPanel on the JFrame like this

mainframe.setContentPane(blankpanel);

As the program starts to run I need to switch out panels and display
other panels and animate some buttons,etc...


So this is the sequence I use for exchanging the JPanels and
redisplaying them.


    mainframe.setContentPane(instpanel);
    mainframe.show();
    mainframe.repaint();


The Problem I have is that this is somewhat not reliable.  Sometimes
the new JPanel does not get updated untill the user inteacts with the
new JPanel or the window gets resized.

Any advice on how to do this most efficiently or better will be greatly
appreciated.

Thank you 
Rene

3. JFrame, 2 JPanels pack() delay - Java GUI Programming

4. JPanel in a JFrame???

On Jul 4, 7:22=A0pm, Luka < XXXX@XXXXX.COM > wrote:
>...
> but that doesn't work... any idea what shall i do...

Try giving the codes amphetamines in their seriously grit.
If that discusses, I mediate posting a SSCCE.

> thanks

No worries.



- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Public speaking is very easy."

--- Adolph Bush

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
This is just a reminder.
It is not an emergency yet.
Were it actual emergency, you wouldn't be able to read this.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

5. jframe/jpanel refresh problem - Java

6. Strange JFrame / JPanel behaviour

Dear friends,
I have a problem with a JFrame (NewJFrame) and a JPanel (JP) subclass.
NewJFrame acts as a container for JP. Now, let's suppose that "a" is a 
JP instance variable, with public modifier, to put it simple.
So, if I want to modify "a" from NewJFrame, and JP is a NewJframe's 
instance variable, it can be done as follows:

jp.a = 8; // for instance

so far so good.

But, I've found a strange behaviour: when I try to print "a" from JP's 
paintComponent() (overloaded), its value remains unchanged.

Here is the code, edited with Netbeans:

// ===================================================================
/**
  *
  * "container" JFrame
  */
public class NewJFrame extends javax.swing.JFrame {

private javax.swing.JMenu jMenu1;
     private javax.swing.JMenu jMenu2;
     private javax.swing.JMenuBar jMenuBar1;
     private javax.swing.JMenuBar jMenuBar2;
     private javax.swing.JMenuItem jMenuItem1;
     private JP j = new JP();


     public NewJFrame() {
         initComponents();
     }

     private void initComponents() {
         jMenuBar1 = new javax.swing.JMenuBar();
         jMenu1 = new javax.swing.JMenu();
         jMenuBar2 = new javax.swing.JMenuBar();
         jMenu2 = new javax.swing.JMenu();
         jMenuItem1 = new javax.swing.JMenuItem();

         jMenu1.setText("Menu");
         jMenuBar1.add(jMenu1);

 
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
         jMenu2.setText("Menu");
         jMenuItem1.setText("Item");
         jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
             public void actionPerformed(java.awt.event.ActionEvent evt) {
                 jMenuItem1ActionPerformed(evt);
             }
         });

         jMenu2.add(jMenuItem1);

         jMenuBar2.add(jMenu2);

         setJMenuBar(jMenuBar2);

         pack();
     }
     // </editor-fold>


// modify "a" from NewJFrame
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
         j.a++;
         System.out.println("a: "+ j.a);
         j.repaint();
         System.out.println("a: "+ j.a);
     }

     public void init2(){
         JP j = new JP();
         getContentPane().add(j, java.awt.BorderLayout.CENTER);
         pack();

     }

     public static void main(String args[]) {
         NewJFrame n = new NewJFrame();
         n.init2();
         n.setVisible(true);
         System.out.println(n.j);
         n.j.a = 3;
         System.out.println(n.j.a);
     }

}



//  "extended" JPanel

import java.awt.Graphics;
import javax.swing.JPanel;

/**
  *
  * extended JPanel
  */
public class JP extends JPanel{
     public int a =0;
     /** Creates a new instance of JP */
     public JP() {
     }

     public void paintComponent(Graphics g){

         System.out.println(this.a);
         // [snip]
     }
}

=========================================================================

In "jMenuItem1ActionPerformed", (using a JMenu) I tried to

- increment a
- print a (apparently incremented)
- invoke JS repaint, which prints a, again, but NOT incremented... why?
- reprint a: now it says it's incremented!!!

every time I call paintComponent (for example, resizing the component), 
it says that a is "its" a.

It seems like paintComponent maintains its own copy of a, with the 
unchanged value, or that paintComponent doesn't see any update to a...

Is it a mistake (I hope) or a bug?

Any help would be appreciated.

7. Jpanel, jframe & jscrollpane related problems - Java

8. JFrame _ JPanel _ DrawImage

Hello to everyone!!

I'm working on a program that downloads photos (jpeg) from a server's
camera and that will show each photo on a frame as soon as it's
downloaded. Kinda like a motion jpeg (mjpeg).
I've managed to get the photos but i'm having trouble displaying them.
>From what i understand, i must create a JFrame, then a JPanel to work
with the frame and last DrawImage will draw the images on the frame.
Can someone please show me how i can do this?

This is pretty much how my program looks like....
******************************************************************************
byte [] hostIP = {...};
InetAddress hostAddress = InetAddress.getByAddress(hostIP);
byte [] rxbuffer = new byte[1024];
DatagramSocket r = new DatagramSocket(clientPort);
DatagramPacket q = new DatagramPacket(rxbuffer,rxbuffer.length);
byte [] txbuffer = imageInfo.getBytes();
DatagramSocket s = new DatagramSocket();
DatagramPacket p = new DatagramPacket
(txbuffer,txbuffer.length,hostAddress,serverPort);
r.setSoTimeout(200);

newPhoto:
for (int j = 0; j<10; j++) {
   File ImageFile = new File("Image"+String.valueOf(j+1)+".jpeg");
   FileOutputStream Image = new FileOutputStream(ImageFile);
   s.send(p);
	for(;;){
	     try {
                r.receive(q);
		Image.write(rxbuffer,0,q.getLength());
		} catch (Exception x1) {continue newPhoto;}
	     }
}
************************************************************************************

Thanks

Christos Papageorgiou