Problemas com JFrame

5 respostas
DANIEL35
Olá amigos, preciso criar uma tela de apresentação para um trabalho, que na verdade ja está criada, mas não consigo colocar vários nomes dentro desta tela sendo que teria que ficar um em baixo do outro. Tentei usar o \n mas não funcionou. Alguem poderia me ajudar nesta formatação do texto? Obrigado. Vejam o código:
import java.awt.*;
import javax.swing.*;

class Teste extends JFrame {

   FontMetrics fm;
   String s = "APENAS TESTES";      
   // JOSE 
   // RODRIGO
   // ANTONIO
   public Teste() {
      setTitle("TESTES- APRESENTAÇÃO");
      Font font = new Font("Jokerman", Font.ITALIC, 36);
      setFont(font);
      fm = getFontMetrics(font);
      setSize(fm.stringWidth(s)+30, fm.getHeight()+60);
      
      setVisible(true);
	  setSize(550, 550);
      setResizable(false);
      setLocationRelativeTo(null);
   }

   public void paint(Graphics g) {
      Insets ins = getInsets();
      int w = getSize().width-ins.left-ins.right;
      int h = getSize().height-ins.top-ins.bottom;

      int centerX = w/2 + ins.left;
      int centerY = h/2 + ins.top;

      g.setColor(Color.red);
      g.fillRect(ins.left, ins.top, w, h);

      g.setColor(Color.yellow);
      g.drawString(
         s, 
         centerX-fm.stringWidth(s)/2, 
         centerY + (fm.getAscent()-fm.getDescent())/2
      );
   }
   static public void main(String[] args) {
      new Teste();
   }
}

5 Respostas

bestlinux

Você não pode usar o Net Beans para criar esta tela ?

DANIEL35

Não, infelizmente não. O professor aboliu o uso de IDEs. Tem quer ser na “unha” (JCreator) mesmo.

Lindberg
javax.swing.table.DefaultTableModel dtm = (javax.swing.table.DefaultTableModel)table.getModel();
	int rows = table.getRowCount();      // pega quant linhas
	rows++;
	
	for (int i = 0; i < quantositens; i++)   
	{
		dtm.setValueAt(meus_dados, linha, coluna); 

            }

ve se ajuda

DANIEL35

Não consegui adaptar seu código, junto ao meu.

Allan_Barcelos

usa o GridLayout

JPanel buttonPanel = new JPanel();
        buttonPanel.setLayout(new GridLayout(1,0));
        
        buttonPanel2.add(button);
        
        add(buttonPanel, BorderLayout.PAGE_START);
Criado 3 de junho de 2010
Ultima resposta 6 de jun. de 2010
Respostas 5
Participantes 4