Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How I can have dynamic multiple Component across a JPanel or JFrame without going out of Screen

 
Kr. Pallav
Ranch Hand
Posts: 32
Eclipse IDE Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to create a JFrame or JPanel ,I am able to generate multiple component getting required value from database value objects.It's working good but problem is if the number of component are more and since there setBounds are dynamically set ,they are going out of screen. How can I add them to a Pane so that it automatically gets scollbar with if number of component increases .
I am setting size of screen using Toolkit and Dimension .
 
Maneesh Godbole
Saloon Keeper
Posts: 11070
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of using setBounds you should be using layout managers
 
Kr. Pallav
Ranch Hand
Posts: 32
Eclipse IDE Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot bro, but using such layout increases the size of the JTextFields and Buttons and all ,I am using GridLayout ,Any suggestions
 
Kr. Pallav
Ranch Hand
Posts: 32
Eclipse IDE Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey I solved it ,using
GridBagConstraints gbc=new GridBagConstraints();
and then
setting Layout as FlowLayout
the code that helped me is like



this code i got from http://www.jchq.net/tutorial/08_01Tut.htm

thanks for help
 
Maneesh Godbole
Saloon Keeper
Posts: 11070
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is what GridLayout does, tries to size all components equally.

If you follow through the link which I had provided earlier, you will notice you have an option of various other layouts. You can even nest containers with different layouts, or even have one complex layout with the GridBagLayout.
If you are not satisfied with these layouts you might want to consider MigLayout

 
Kr. Pallav
Ranch Hand
Posts: 32
Eclipse IDE Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Bhai,Thanks a lot for the help ,you guys are awesome ,doing a tremendous job of sharing the knowledge ,I will try my level best to contribute to open source technology ,Your team is really helpful and inspiring many like me.Hats off to coderanch
 
Rob Camick
Ranch Hand
Posts: 2599
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to create a JFrame or JPanel ,I


In the solution you posted above you are using a Frame and a Panel. I suggest you stick with the Swing components (JFrame and JPanel) since more development is done in Swing than AWT.
 
Kr. Pallav
Ranch Hand
Posts: 32
Eclipse IDE Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Rob Camick , I am sorry for little wrong approach while answering , I am using JFrame and JSwing only , I only used the GridBagConstraints and modified accordingly
,dear .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic