Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Add JPanel to JPanel  RSS feed

 
zero Corner
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Same old staff inner JPanel cannot be seen ..... i being see many web site or forum for solution, not much helping.......

currently i writting a custom class to add multiple list to a jpanel.
then i add the jpanel to a Jscrollpane(cause i wan to resize whole list rather than all my list got JScrollPane)

finally i add the JScrollPane to the outer jpanel which the reference being pass into a method call UpdatePanel(Jpanel jp)

i know that the jpanel add dynamically to a outer jpanel through coding will not be seen unless it being refresh, those method being suggest in the website like validate,invalidate,repaint also not working...

forsure some expert in this forum solve this problem before ...

cause the source code is more that 3 page so i guess quite hard to post it in...

please help me..... SOS...... need to finish my assignment
Thanks in advance!!!
 
Campbell Ritchie
Marshal
Posts: 55715
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to our GUIs forum.
Start with something simple: add a Scroll Pane, then the panel, the add to that. See how far you get before you have problems. And don't try to suggest your question is in any way more urgent than others.
 
Rob Camick
Ranch Hand
Posts: 2800
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is NOT a problem. The solution IS simple.

You create your scrollpane something like:



If you make changes to the panel after the GUI is visible then your code should be:



Thats is, there is no trick. As long as your components have a preferred size they will appear properly.

If it doesn't work for you then you are doing something extremely different than the norm and there is no way we can guess what it might be since we are not mind readers.

If you need further help then you need to create a SSCCE (Short, Self Contained, Compilable and Executable, Example Program), that demonstrates the incorrect behaviour.

Don't forget to use the Code Formatting Tags so the posted code retains its original formatting. That is done by selecting the code and then clicking on the "Code" button above the question input area.


 
zero Corner
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

ListTitle is a Jlabel array
length is the total number of list require which is user specify
this is part of my code....

i try your solution already Rob Camick, thanks for your reply

after the component is visible i cannot make it refresh some how...

now i kind of stuck in the middle... although there is some alternative way but it is ugly code
 
Rob Camick
Ranch Hand
Posts: 2800
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is NOT a SSCCE!
 
zero Corner
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


i use netbean to create the GUI so the initComponents method just ignore the core problem is inside the updatepanel method
Sorry for the code length... cause using the netbean....
thanls again for your patient Rob.
 
Rob Camick
Ranch Hand
Posts: 2800
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I don't use an IDE to generate my code.

I have no idea how GroupLayout works, but you did not set any constraints. Notice all the bloated IDE code that sets GroupLayout constraints. If you want to use a GroupLayout then you need to learn how the constraints work so you can use your own constraints when you add the panel.

My suggestion is to do the layout manually so you don't have to worry about this.
 
Rob Camick
Ranch Hand
Posts: 2800
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but i think the main problem is because the scrollpane is add to a JPanel after the UI is generated


The problem is you are using a GroupLayout and you don't know how to set up the constraints when you add the new panel.

i face this problem before when i add inner JPanel to a outer JPanel after the UI is generated, should not much related to the layout problem..


This is not a problem with other layout mangers. Most don'e use constraints or they are easier to understand.

i read through many webpage but none of them lead to a direct solution.... any idea???


I already gave you the solution. Either learn how to use a GroupLayout or use other layout managers and design your GUI manually without using the IDE.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!