• 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

Problem laying out panels in an Applet

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi. I'm trying to lay out panels in a test applet shown below. I want to have two panels each with a different layout manager. I want the first panel to always display above the other one when the applet is launched. At present, the second panel appears directly after the first panel. Is there anyway I can get around this so I can achieve the layout I want? I did get it working using the JApplet class but I don't like the look and feel of that -- I'm doing early gui testing for an applet to mimic a standard html web form for a college project and the Applet class is the one I have to use.
I also tried putting the two panels in a single container and applying a border layout to both panels when added to the container (north and south respectively). Although the file compiles, nothing displays in the Applet when I run the appletviewer when attempting that approach. It just says Applet initiated and remains a blank window).
Here is the source code for the one that does display but not the way I'd like: would really appreciate any tips or web references anybody can provide. I've looked at Sun's tutorials and my textbook but they all use JApplet examples although they do say it should be possible to position panels too as they are containers. Let me know if I have that wrong. Thanks for any help in advance.
//
// TESTING: MULTIPLE LAYOUTS USING PANELS COMBINED WITH APPLET CLASS NOT JAPPLET
//
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class NetApplet4 extends Applet
{
private TextField message = null ;
private Button button = null;
private TextField message2 = null ;
private Button button2 = null;
private boolean pressed = false;

// extra test variables
private Button button3 = null;
private TextField message3 = null;
private Button button4 = null;
private TextField message4 = null;
public NetApplet4()
{
}
public void init()
{
// set default window size
resize(750, 400);
// declare a new panel
Panel pnlDisplay1 = new Panel();

// assign a layout manager to the panel
pnlDisplay1.setLayout(new GridLayout(0,2));

// instantiate objects for panel 1
button = new Button("PRESS ME");
message = new TextField(30);
message.setEditable(false);
button3 = new Button("Button 3");
message3 = new TextField("Message 3");
button4 = new Button("Button 4");
message4 = new TextField("Message 4");
// add objects to panel 1
pnlDisplay1.add(button);
pnlDisplay1.add(message);
pnlDisplay1.add(button3);
pnlDisplay1.add(message3);
pnlDisplay1.add(button4);
pnlDisplay1.add(message4);

// add the panel1
add(pnlDisplay1, BorderLayout.NORTH);
// declare a new panel
Panel pnlDisplay2 = new Panel();

// assign a layout manager to the panel
pnlDisplay2.setLayout(new FlowLayout());
// instantiate objects for panel 2
button2 = new Button("Submit Ticket Order Online");
// add objects to panel 2
pnlDisplay2.add(button2);
// add the panel2
add(pnlDisplay2, BorderLayout.SOUTH);

}
} // end NetApplet4 class
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Neil Guerin
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have just tested this code you provided and it does exactly what I was looking for. Thank you so much for your help. Really appreciate it.
 
When you have exhausted all possibilities, remember this: you haven't - Edison. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic