JPanel resize with mouse problem

I

iherage

Hello,

I have a question about how to resize the JPanel with mouse.

There are mainPanel, jPanel1 and jPanel2. The Layout of mainPanel is
BorderLayout. jPanel1 is added to the west while jPanel2 is added to
the center.
What I am going to implement is to move the mouse over the border of
jPanel1, then it shall change to Cursor.E_RESIZE_CURSOR. And with the
move of the mouse, jPanel1 and jPanel2 shall be resized.

Anyone has ideas about this? I have googled again and again and try it
myself. But I still cannot make it.

Can anyone provide some help for me. Thank you for the help.
 
K

Knute Johnson

Hello,

I have a question about how to resize the JPanel with mouse.

There are mainPanel, jPanel1 and jPanel2. The Layout of mainPanel is
BorderLayout. jPanel1 is added to the west while jPanel2 is added to
the center.
What I am going to implement is to move the mouse over the border of
jPanel1, then it shall change to Cursor.E_RESIZE_CURSOR. And with the
move of the mouse, jPanel1 and jPanel2 shall be resized.

Anyone has ideas about this? I have googled again and again and try it
myself. But I still cannot make it.

Can anyone provide some help for me. Thank you for the help.

I don't know how to do that but why don't you just use
a JFrame instead. It will do exactly what you want and
handle the cursor and everything.
 
R

Roedy Green

I have a question about how to resize the JPanel with mouse.

Resizing a panel implies other Components will have to change size and
position as well. Perhaps you might want to rethink and use Frames or
JFrames which can be sized or resized independently, without any
programming effort.

The problem I foresee is every micro change implies a validate/repaint
of the whole app. That might not be smooth or fast enough..

You can check by simulating with timed programmatic micro changes ho
the panels with validate/repaints, or by seeing the response to
changing the shape of the entire app Frame. You want to run these
experiments on the least skookum computer that will be running your
app.
 
I

iherage

Resizing a panel implies other Components will have to change size and
position as well. Perhaps you might want to rethink and use Frames or
JFrames which can be sized or resized independently, without any
programming effort.

The problem I foresee is every micro change implies a validate/repaint
of the whole app. That might not be smooth or fast enough..

You can check by simulating with timed programmatic micro changes ho
the panels with validate/repaints, or by seeing the response to
changing the shape of the entire app Frame. You want to run these
experiments on the least skookum computer that will be running your
app.

The two panels are resided in the mainPanel. And I want to change one
panel's width without the mouse.Of course the other pane's width will
be affected.
There are a few questions left.
1. Which component should register to listen to the event?
2. How to determine the mouse is moving over the border of the two
panels.
3. I think the method that will be used is the setPerferredSize(), but
I do not the detailed implementation.

I have tried myself by implementing a simple program but failed.
Anyone who has experience in the java gui programming knows this?
Please give some hints. Thank you for the help.
 
K

Knute Johnson

The two panels are resided in the mainPanel. And I want to change one
panel's width without the mouse.Of course the other pane's width will
be affected.
There are a few questions left.
1. Which component should register to listen to the event?
2. How to determine the mouse is moving over the border of the two
panels.
3. I think the method that will be used is the setPerferredSize(), but
I do not the detailed implementation.

I have tried myself by implementing a simple program but failed.
Anyone who has experience in the java gui programming knows this?
Please give some hints. Thank you for the help.

Until you explain exactly what you want your GUI to do we are going to
have a hard time helping you. So please describe simply what you want
your GUI to do.
 
A

Andrew Thompson

On Sep 26, 7:08 am, (e-mail address removed) wrote:
....
I have a question about how to resize the JPanel with mouse.

Put it in an JSplitPane.

As for your latter question 'without mouse', try
JSplitPane + JButton(s) - "Bigger"/"Smaller".

But I say that with little more understanding of
your questions than as expressed by Knute.

Andrew T.
 
A

Andrew Thompson

Andrew said:
On Sep 26, 7:08 am, (e-mail address removed) wrote:
...

Put it in an JSplitPane.

As for your latter question 'without mouse', try
JSplitPane + JButton(s) - "Bigger"/"Smaller".

I got an email from the OP stating..
"no. I am asked to use the just the JPanel, not JSplitPane."

Now, in case you are confused. Do *not* send me email.
I reposted your comment here on the assumption that you
simply clicked the wrong button when replying.

Please take more care in future which buttons you click,
as further emails from you to me will be deleted without
being read.

--
Andrew Thompson
http://www.athompson.info/andrew/

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-general/200709/1
 
I

iherage

I got an email from the OP stating..
"no. I am asked to use the just the JPanel, not JSplitPane."

Now, in case you are confused. Do *not* send me email.
I reposted your comment here on the assumption that you
simply clicked the wrong button when replying.

Please take more care in future which buttons you click,
as further emails from you to me will be deleted without
being read.

Sorry. Yes I clicked the wrong button. I am very sorry for that!
I think the Split Panes will work now.

Thank you very much
 
A

Andrew Thompson

Sorry. Yes I clicked the wrong button. I am very sorry for that!

It's cool. ( I am saying that, guessing that means
you intend to take a little more care with the buttons. ;)
I think the Split Panes will work now.

Excellent. Glad you got a workable solution, &
since it is more like what the end-user would expect,
I am thinking they will be grateful as well. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top