• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Jpanels and Jscrollpanels

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am reallllly hoping you guys can help me.

I have a small gui app, it is using the mvc model and i am having issues with the listner on the jscrollpanel.

I have the main jpanel, in it is 3 area, the center being for my data. this is a gridlayout jpanel. I had a loop which put another jpanel in it. The listener was attached to middle panel.this works, but to meet the requirements of my assignment i need to use the jscrollpanel. I have added this to the middle panel and then added the final panel to it. This works great excpet now i cannnot get the jscrollpanel to trigger the listener. Any idea would be great. I have the code but it is long.
 
Marshal
Posts: 79177
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

What sort of Listener is it?
Don't know, but I think we shall need to see your c ode.
 
Oliver Higgins
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Welcome to the Ranch

What sort of Listener is it?
Don't know, but I think we shall need to see your c ode.



Cheers, this is the View part of my work

Line 129 is where i need to add my object so the controller will see it with the listener. 139-200ish is where the gui is put together to make my grid. I have added screenshot to give you an idea.


homecad.jpg
[Thumbnail for homecad.jpg]
 
Oliver Higgins
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
at line 186

//content2.add(scrollPane, BorderLayout.CENTER);
content2.add(j_x, BorderLayout.CENTER);

if i use this instead my programs functions work perfect but i do not get my scroll bars etc.
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why do you want to a scroll pane in a method called xxxListener? That method has a confusing name; it should have add or remove in its name. You should be adding the scroll panes in the constructor or "setUpGUI" method.
 
Oliver Higgins
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Why do you want to a scroll pane in a method called xxxListener? That method has a confusing name; it should have add or remove in its name. You should be adding the scroll panes in the constructor or "setUpGUI" method.




Thanks Campbell

It is called from the constructor.

The grid redraws itself after each click or double click but when i implement the jscrollpane i no longer get the mouse event to fire.
 
Oliver Higgins
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
maybe if i explain it this way;

For my GUI i the following
JFrame
>JPanel (nav bar)
>JPanel (gridlayout dynamic based on house size)
>> JPanel(each grid/cell)
>>> Componts (label etc)
>> JPanel (Stat bar)
This works fine to select and work with my rooms(part of the project) in each grid. I have the listener attached to the gridlayout panel, so i know where my mouse has clicked and therefore which grid it belongs to. The listener is the mouselistener on the JPanel.

But when i place a JScrollPane in here;
JFrame
>JPanel (nav bar)
>JPanel (gridlayout dynamic based on house size)
>>jScrollPane
>>>JPanel(each grid/cell)
>>>>Components (label etc)
>>>JPanel (Stat bar)
To give me the scroll bars for each room, my gui no longer accepts the mouse event (it does but not on the gridlayout JPanel as it did before). Does anybody know how i can overide the JScrollPane and let my JPanel underneath receive the event?
I am struggle to find a way to do this that will adhere to the MVC structure. As the code to check and prepare everything is in the controller which just hands the basic info over to the view to repaint it all.
Or i am just completely going in the wrong direction
 
Ranch Hand
Posts: 34
Netbeans IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Oliver. i think the problem is JScrollPane because it is gets mouse event and do not let JPanel get mouse event. you should use dispatchEvent to get mouse event from JScrollPane and send it to JPanel.
 
Oliver Higgins
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Javad Rashidi wrote:Hi Oliver. i think the problem is JScrollPane because it is gets mouse event and do not let JPanel get mouse event. you should use dispatchEvent to get mouse event from JScrollPane and send it to JPanel.



Do you have an example? I am basically trying to do this

Add JScrollPane to Jpanel
Send click from JscrollPane to JPanel.
 
Javad Rashidi
Ranch Hand
Posts: 34
Netbeans IDE MySQL Database Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here is an example:

parent: component that you want to recive the MouseEvent fom this component
 
Oliver Higgins
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thankyou for that, i still fighting with it. my "parent" is called content2 and it is a JPanel. I changed the JComponent to JPanel, but i;m not sure which "parent" in the code to change to content2....??? (I am really appreciating your help)
 
Javad Rashidi
Ranch Hand
Posts: 34
Netbeans IDE MySQL Database Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you should pass content2 to constructor of MyScrollPane because you add MyScrollPane to content2. when mouse event happen on MyScrollPane it dispatch to content2. you don't need to change parent to content2.
 
Oliver Higgins
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
like this
 
Javad Rashidi
Ranch Hand
Posts: 34
Netbeans IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes exactly
 
reply
    Bookmark Topic Watch Topic
  • New Topic