I have a Toolbar, and I want to make a settings bar in it. However, in order not to occupy space, I would like to hide / minimize it, something like the teamviewer chat.
My ToolBar (it's inside a main screen)
Container contentPane = this.getContentPane();
contentPane.add(toolBar, BorderLayout.SOUTH);
toolBar.setFloatable(false);// não deixa ToolBar mudar de lugar.
JLabel label = new JLabel(" Configurações ");
toolBar.add(label);
toolBar.add(botaoConfig);
botaoConfig.addActionListener(this);
botaoConfig.setPreferredSize(new Dimension(30, 30));
I'm going to put an illustration to help you with your understanding:
Well-summedexample:
packagetestes;importjava.awt.BorderLayout;importjava.awt.Color;importjava.awt.Container;importjava.awt.Dimension;importstaticjava.awt.Frame.MAXIMIZED_BOTH;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjavax.swing.JButton;importjavax.swing.JDesktopPane;importjavax.swing.JFrame;importstaticjavax.swing.JFrame.EXIT_ON_CLOSE;importjavax.swing.JLabel;importjavax.swing.JMenu;importjavax.swing.JMenuBar;importjavax.swing.JMenuItem;importjavax.swing.JToolBar;publicclassTelaSistemaextendsJFrameimplementsActionListener{publicJDesktopPanejdp=newJDesktopPane();publicJMenuBarjmb=newJMenuBar();publicJMenujmCadastros=newJMenu("Cadastros");
public JMenuItem jmiEstado = new JMenuItem("Estado");
JToolBar toolBar = new JToolBar();
JButton botaoConfig = new JButton("Config");
public TelaSistema() {
Container contentPane = this.getContentPane();
contentPane.add(toolBar, BorderLayout.EAST);
toolBar.setFloatable(false);// não deixa ToolBar mudar de lugar.
JLabel label = new JLabel(" Configurações ");
toolBar.add(label);
toolBar.add(botaoConfig);
botaoConfig.addActionListener(this);
botaoConfig.setPreferredSize(new Dimension(30, 30));
toolBar.setBackground(new Color(230, 230, 230));
// setSize(800, 600);
setExtendedState(MAXIMIZED_BOTH);
setTitle("Sistema");
getContentPane().add(jdp);
setJMenuBar(jmb);
jmb.add(jmCadastros);
adicionaJMenuItem(jmCadastros, jmiEstado);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
private void adicionaJMenuItem(JMenu menu, JMenuItem item) {
menu.add(item);
item.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent ae)
{
}
public static void main(String[] args)
{
TelaSistema tela = new TelaSistema();
}
}