Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

layers  RSS feed

 
basia fish
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • 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();
}
}
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!