• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

layers

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

my gui:
has:
1. toolbar
2. main panel divided into two panels (left and right)

depending on which button in toolbar is presed i would like to display diffrent panels in those two panels

i tried putting those diffrent panels into diffrent layers and then calling diffrent layers according to which button is presed

however it is not really working
i am posting my simplified code

any help would be appreciated
if there is better way to implement it please help

bbarbara okupna

public class mainClass extends JFrame implements ActionListener
{
JLayeredPane layeredPaneLeft;
JFrame frame;
JPanel leftPanelAddEdit;

public void createAndDisplayGui()
{
frame = new JFrame("HelloWorldSwing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(1200,1000);

JPanel leftPanel = new JPanel();
leftPanel.setBorder(BorderFactory.createTitledBorder("sdsdsds"));

JToolBar toolBar = new JToolBar();

toolBar.add(Button("Add New"));

JPanel mainPanel = new JPanel();


leftPanelAddEdit = new JPanel();
leftPanelAddEdit.add(leftPanel);


layeredPaneLeft = new JLayeredPane();
layeredPaneLeft.add(leftPanelAddEdit, 1);

mainPanel.add(layeredPaneLeft);


frame.getContentPane().add(toolBar,BorderLayout.NORTH);
frame.getContentPane().add(layeredPaneLeft,BorderLayout.WEST);

frame.show();


}



public JButton Button( String name)
{
JButton button = new JButton(name);
button.setActionCommand(name);
button.addActionListener(this);
return button;

}

public void actionPerformed(ActionEvent e) {
if ("Add New".equals(e.getActionCommand())) {

layeredPaneLeft.moveToFront(leftPanelAddEdit );

}
}

public static void main(String[] args)
{
mainClass f = new mainClass();
f.mainClassnn();
}
}
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
barbzx

Welcome to Javaranch!

As you know this is a great community in which to learn Java and we don't have too many rules around here, but we do have a Naming Policy. Please read this policy and adjust your display name accordingly.

You can change your display name here.

Thanks.
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
CardLayout does a nice job of managing panels in a small space. It has a show method that will show any specific panel

if you don't like the next and previous methods. See CardLayout api for more.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic