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

set size of jpanel  RSS feed

 
Habib Ghayoumi
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I am designing a form using swing components in my applet. I want to have a strip on top of my form with a title in it. I am using jpanel and color bachground for it. My problem is that I cannot decrease height of the jpanel more than a minimum size. It covers one fourth part of my form. below code:

JPanel jpRow0 = new JPanel(new FlowLayout(FlowLayout.RIGHT, hgap, vgap));
jpRow0.computeVisibleRect();
jpRow0.setPreferredSize(new Dimension(695, 1)); // does not work !!!
jpRow0.setBackground(new Color(0,0,128));
JLabel lblFormTitle = new JLabel(TitlePersian.REPORT + " " + TitlePersian.INVOICES_ + " " + TitlePersian.CONTRACT);
lblFormTitle.setFont(Global.font);
lblFormTitle.setForeground(new Color(255,255,255));
jpRow0.add(lblFormTitle);
getContentPane().add(jpRow0);

does anyone has experienced my problem and has a solution? I would be thankfull if share your knowledge .
Thanks in advance
Habib

 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Habib,
Welcome to the ranch, we are happy to have you here

Instead of nesting panels, try adding the JLabel instance to the panel directly (Panel will have a border layout and label constraints would be BorderLayout.NORTH)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!