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. JPanel in a JFrame??? - Java

4. jframe/jpanel refresh problem

Here is my problem.  I have an application that keeps a running
checklist of currently running windows.  Everything seems to work fine,
except I have a problem refreshing the JPanel/JFrame/JScrollPane (not
sure which?) when I add and remove items from the list.

I have a JFrame, with 2 JPanels (the first contains other buttons for
the form).  Then I have a JScroll Pane which displays the contents of
another panel: an array of checkboxes, one checkbox for each item in my
window list.

I first set up the m_Display panel with all the buttons and other text
fields, etc.  Then I set up the scroll pane m_Scroll, with another
panel m_Panel, then add the scroll pane to the first panel.  Then I set
the panel that contains everything to be the content pane of the frame.


Everytime I want to refresh, I send a message to the form, remove all
the items currently in the list, and then add all the new incoming
ones.  The frame properly refreshes when I add items (if there are 3
items, and I send a message with 4 or 5, the new list automatically
pops up).  But if I have 3 items in the list, and I update it with 2,
the frame will not redraw until I resize or move it off the screen,
etc.  I have tried an endless combination of validate, invalidate,
pack, etc. on all the components.  I don't know if something is wrong
with my setup of components, or something is out of order.  If anyone
could help me out I'd really appreciate it.  An excerpt of my code is
included.  Thanks a lot.


	public void Display()
	{
		try
		{
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		}
		catch(Exception e)
		{
			JFrame.setDefaultLookAndFeelDecorated(true);
		}

		//set up and position the JDialog frame
		setPreferredSize(new Dimension(310, 500));
		Dimension d = getToolkit().getScreenSize();
		Point p = new Point((d.width-450)/2, (d.height-100)/2);
		setLocation(p);

		m_Display = new JPanel();
		JLabel text = new JLabel("Please enter the IP Address of the server
in the box below:");
		m_Input = new JTextField();
		m_Panel = new JPanel();
		m_Popup = new JPopupMenu();

		//set up the buttons: ok, cancel, start, refresh
		ok = new JButton("Connect");
		cancel = new JButton("Cancel");
		start = new JButton("Start");
		refresh = new JButton("Refresh");

		//set up the text field for input
		m_Input.setPreferredSize(new Dimension(270, 20));
		//m_Input.setText("localhost");

		m_CheckBox = new JCheckBox("Display Window List", true);

		m_Display.add(text);
		m_Display.add(m_Input);
		m_Display.add(m_CheckBox);
		m_Display.add(ok);
		m_Display.add(cancel);

		m_Panel.setBackground(Color.WHITE);

		m_Scroll = new JScrollPane(m_Panel);
		m_Scroll.setPreferredSize(new Dimension(280,350));
		m_Scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
		m_Scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
		m_Scroll.setBackground(Color.WHITE);


		m_Display.add(m_Scroll);
		m_Display.add(start);
		m_Display.add(refresh);

		//add action listener to buttons and text field
		ActionListener buttonaction = new buttonAction();
		cancel.addActionListener(buttonaction);
        ok.addActionListener(buttonaction);
		refresh.addActionListener(buttonaction);
		start.addActionListener(buttonaction);
		m_CheckBox.addItemListener(new CheckboxListener());
        m_Input.requestFocus();
        m_Input.addActionListener(new WRAKeyboardListener());

		//display the dialog
        setContentPane(m_Display);
		//setGlassPane(m_GlassPanel);

		m_Display.setOpaque(true);
		pack();
		setVisible(true);
	}

//refresh function

public void Refresh(WindowListDataMessage msg)
	{
		System.out.println("refresh");
		m_numWindows = msg.getNumWindows();
		m_TitleList = msg.getWindowTitles();
		m_GuidList = msg.getGuids();
		m_CheckedFlags = msg.getFlags();
		//first clear the existing list
		for(int i = 0; i < m_numCheckboxes; i++)
		{
			m_Panel.remove(m_checkBoxes[i]);
		}
		m_numCheckboxes = 0;
		//14 is the number of items we can correctly display without a
vertical scrollbar
		if(m_numWindows < 14)
			m_Panel.setLayout(new GridLayout(14, 0));
		else
		//if there are more than 14 windows, set up a vertical scrollbar
			m_Panel.setLayout(new GridLayout(m_numWindows, 0));

		//populate the check box list
		m_checkBoxes = new JCheckBox[m_numWindows];
		for(int i = 0; i < msg.getNumWindows(); i++)
		{
			m_checkBoxes[i] = new JCheckBox(m_TitleList[i]);
			m_checkBoxes[i].setBackground(Color.WHITE);
			m_Panel.add(m_checkBoxes[i]);
			m_checkBoxes[i].addItemListener(new CheckboxListener());
			if(m_CheckedFlags[i] == 1)
				m_checkBoxes[i].setSelected(true);
			m_numCheckboxes++;
		}
		m_Display.invalidate();
		//m_Display.pack();
		//m_Scroll.pack();
		m_Scroll.invalidate();
		validate();
		pack();
	}

5. Strange JFrame / JPanel behaviour - Java

6. Jpanel, jframe & jscrollpane related problems

Hi

This is my code:

        Grafi smart1 = new Grafi(nn, testing, n_archi, max*160+60);
        int width1 = 0;
        int height1 = 0;
        width1=max*160+60;
        if (ncompat==1) {
          height1=(int)((nn*30))+60;
        } else {
          height1=(int)((nn*30)/(ncompat-1))+60;
        }
        smart1.setPreferredSize(new Dimension(width1, height1));
        JScrollPane scrollpane1 = new JScrollPane(smart1);
        JFrame f1 = new JFrame("MyFindeR - Direct Strand");
        f1.setContentPane(scrollpane1);
        f1.setSize(800, 600);
        f1.setVisible(true);

Grafi is a class which extends JPanel, and smart1 is an instance of Grafi on
which there are drawed some ractangles and lines. My smart1 is very huge
and everytime I use repaint(), it takes 7-8 seconds to repaint it all. So,
I would like to use the repaint(x,y,width,height) feature, and repaint only
the visible part of smart1. In that case width and height would be 800 and
600 (frame size), but, how can I find x & y? I need x and y of smart1, that
corresponds to the point (0,0) of the frame. Is there a way to find them?
Thnx

7. JFrame _ JPanel _ DrawImage - Java

8. get the value of the position of JPanel inside the JFrame

Hi Thomas,
What's the problem ?
I don't understand what you mean.
I have a JFrame and inside two JPanel one of them is on NORTH and the second
one is on the SOUTH.
And When I get the Container which is the JPanel (please see code below), I
would like to know if this one is in the north on the JFrame
or in the SOUTH or in the EAST, WEST or CENTER.
I would to know how to get the value of the position of this JPanel inside
the JFrame.
That 's all.
If you can helpme about this it will be very great.
Thanks a lot
Best regards
Frederic.

if (c instanceof JPanel){

String panel = "panel"+compPanel;

parentPanel = panel;

String allocPanel = ((Container)c).getClass().getName()+" "+panel+"= new
"+((Container)c).getClass().getName()+"();";

String namePanel = panel+".setName(\""+((Container)c).getName()+"\");";

//**********    my proble is to do a array with the name of
BorderLayout.NORTH, etc...)   *****//

String addPanel = allocPanel+"
this.getContentPane().add("+panel+","+borderLayout[compborderLayout]+");";

compborderLayout++;

compPanel++;

bodyProgram.append(addPanel+" "+namePanel);

sons = true;




Les informations contenues dans le present message et dans tous les
fichiers electroniques qui y sont attaches, sont strictement
confidentielles et ne sont destinees qu'a l'usage de la personne dont le
nom apparait ci-dessus et de toute autre personne specifiquement
autorisee a les recevoir. Si vous n'etes pas la personne a qui ces
informations sont destinees, nous vous informons qu'il est strictement
interdit de les diffuser, de les utiliser ou d'en faire des copies. Si
vous avez recu ce message electronique par erreur, ou si des problemes
de transmission surviennent, nous vous remercions d'en aviser
immediatement l'expediteur ou de telephoner au (33-1) 41.48.10.19.
Attention : Tout message electronique est susceptible d'alteration.
AONIX decline toute responsabilite au titre de ce message s'il a ete
altere, deforme ou falsifi



This message and any attachments (the  message ) is intended solely
for the addressees and is confidential.  If you receive this message in
error, please delete it and immediately notify the sender (33-1)
41.48.10.19. Any use not in accord with its purpose, any dissemination
or disclosure, either whole or partial, is prohibited except formal
approval. The internet can not guarantee the integrity of this message.
AONIX shall not therefore be liable for the message if modified.