StatusBar [Resolvido]

4 respostas
C

Boa Tarde, vcs podem me ajudar a criar uma statusbar no JAVA? Antes que perguntem é statusbar e não progressbar

A statusbar fica em uma classe separa, por exemplo, do menu?

4 Respostas

V

Não existe o componente de StatusBar em Java. O máximo que você pode fazer é inserir na parte South de um BorderLayout um JPanel, e por lá colocar algumas JLabels.
Ou procurar alguma classe assim em bibliotecas de terceiros, como o SwingX.

Y
eu faço assim:
public class StatusBar extends JLabel {

	private static final long serialVersionUID = 1L;

	public StatusBar() {
		super.setText("AUTOR:MÁRIO YHHIK\r EMAIL: [email removido]");
		setLayout(new BorderLayout());
		setPreferredSize(new Dimension(10, 23));

		JPanel rightPanel = new JPanel(new BorderLayout());
		rightPanel.add(new JLabel(new AngledLinesWindowsCornerIcon()),
				BorderLayout.SOUTH);
		rightPanel.setOpaque(false);

		add(rightPanel, BorderLayout.EAST);
		setBackground(SystemColor.control);
	}

	protected void paintComponent(Graphics g) {
		super.paintComponent(g);

		int y = 0;
		g.setColor(new Color(156, 154, 140));
		g.drawLine(0, y, getWidth(), y);
		y++;
		g.setColor(new Color(196, 194, 183));
		g.drawLine(0, y, getWidth(), y);
		y++;
		g.setColor(new Color(218, 215, 201));
		g.drawLine(0, y, getWidth(), y);
		y++;
		g.setColor(new Color(233, 231, 217));
		g.drawLine(0, y, getWidth(), y);

		y = getHeight() - 3;
		g.setColor(new Color(233, 232, 218));
		g.drawLine(0, y, getWidth(), y);
		y++;
		g.setColor(new Color(233, 231, 216));
		g.drawLine(0, y, getWidth(), y);
		y = getHeight() - 1;
		g.setColor(new Color(221, 221, 220));
		g.drawLine(0, y, getWidth(), y);

	}
}

class AngledLinesWindowsCornerIcon implements Icon {
	private static final Color WHITE_LINE_COLOR = new Color(255, 255, 255);

	private static final Color GRAY_LINE_COLOR = new Color(172, 168, 153);
	private static final int WIDTH = 13;

	private static final int HEIGHT = 13;

	public int getIconHeight() {
		return WIDTH;
	}

	public int getIconWidth() {
		return HEIGHT;
	}
	
	public void paintIcon(Component c, Graphics g, int x, int y) {
		g.setColor(WHITE_LINE_COLOR);
		g.drawLine(0, 12, 12, 0);
		g.drawLine(5, 12, 12, 5);
		g.drawLine(10, 12, 12, 10);

		g.setColor(GRAY_LINE_COLOR);
		g.drawLine(1, 12, 12, 1);
		g.drawLine(2, 12, 12, 2);
		g.drawLine(3, 12, 12, 3);

		g.drawLine(6, 12, 12, 6);
		g.drawLine(7, 12, 12, 7);
		g.drawLine(8, 12, 12, 8);

		g.drawLine(11, 12, 12, 11);
		g.drawLine(12, 12, 12, 12);

	}
}
F

Eu uso BorderLayout, adiciono um JPanel no South e seto ele para BoxLayout depois só vou adicionando os JSeparator como preciso.

mais ou menos assim.

public class MeuFrame extends JFrame{
      private JPanel north, center, south;
      public MeuFrame(){
         north = new JPanel();
         center = new JPanel();
         south = new JPanel();

         south.setLayout(new BoxLayout(south, 1));
         south.add(new JLabel("Usuario:"));
         south.add(new JSeparator(1));
         south.add(new JLabel("Relogio:"));
         south.add(new JSeparator(1));

         this.setLayout(new BorderLayout(1,1));
         this.add(north, BorderLayout.NORTH))
         this.add(center, BorderLayout.CENTER));
         this.add(south, BorderLayout.SOUTH));         
      }


}

Seria mais ou menos isso, nem testei, escrevi aqui diretamente…Usando NetBeans ou Eclipse(WindowBuilder) fica mais facil fazer isso.

t+ e boa sorte.

C

Obrigada pelas dicas :smiley:

Criado 21 de fevereiro de 2012
Ultima resposta 21 de fev. de 2012
Respostas 4
Participantes 4