JTextField

Galera é o seguinte:
Estu usando um JTextField e preciso justificar um texto nele.
como posso fazer?
Já li a respeito de fazer ultilizando html…
só que eu não sei como fazer…
se alguém tiver alguma solução aí…
posta pfv!!
vlwwww!!!
:smiley:

Não entendi. Você tem um texto longo e com várias em um JTextField, é isso?
Se sim, sugiro que você substitua este JTextField por um JTextArea, componente específico para receber textos longos e com várias linhas.
De qualquer forma, desconheço uma solução trivial para deixar o texto justificado.
Talvez a classe Document te ajude:

http://java.sun.com/j2se/1.4.2/docs/api/org/w3c/dom/Document.html
http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/text/JTextComponent.html#setDocument(javax.swing.text.Document)

Não sei se isto te ajuda é a forma de posicionamento do texto com relação ao componente JTextField

jTextField1.setHorizontalAlignment(JTextField.HORIZONTAL);

Ai vc define como será este posicionamento

David, até onde sei, desconheço que um JTextArea tenha métodos de formatação no texto que está dentro dele, por justa causa ultilizo um JTextField.
Já tentei ultilizar um JTextArea, mas a saida não foi nada comparada com o previsto
=\

Qual ferramenta esta usando???

Talves esse tópico te ajude http://www.guj.com.br/posts/list/27470.java

Fioline, mudei agora para um JTextPane…

Este programa mostra um JTextPane justificado. Clique em “justified” para ver o efeito.

(Código adaptado de http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4263904 ; só funciona corretamente a partir do Java 6.0, ou então no 5.0 update 6 ou superior.)

import javax.swing.text.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

public class TestAlignment extends JFrame
{
  private JTextPane myTextPane;
  private SimpleAttributeSet sas;
  private StyledDocument theDocument;

  public TestAlignment()
  {
    super();

    setSize( 500, 500);
    getContentPane().setLayout( new GridLayout( 1, 2));

    myTextPane = new JTextPane();
    myTextPane.setSize( 250, 250);
    getContentPane().add( myTextPane);
    myTextPane.setText( "A very, very, very, very, very long line of text for testing justified alignment");

    sas = new SimpleAttributeSet();

    JButton leftAlignButton = new JButton( "left");
    JButton rightAlignButton = new JButton( "right");
    JButton centreButton = new JButton( "centered");
    JButton justifyButton = new JButton( "justified");

    JPanel buttonPanel = new JPanel();

    leftAlignButton.addActionListener( new ActionListener() {
      public void actionPerformed( ActionEvent e)
      {
        StyleConstants.setAlignment( sas, StyleConstants.ALIGN_LEFT);
        myTextPane.setParagraphAttributes( sas, false);

        myTextPane.repaint();
      }
    });

    rightAlignButton.addActionListener( new ActionListener() {
      public void actionPerformed( ActionEvent e)
      {
        StyleConstants.setAlignment( sas, StyleConstants.ALIGN_RIGHT);
        myTextPane.setParagraphAttributes( sas, false);

        myTextPane.repaint();
      }
    });

    centreButton.addActionListener( new ActionListener() {
      public void actionPerformed( ActionEvent e)
      {
        StyleConstants.setAlignment( sas, StyleConstants.ALIGN_CENTER);
        myTextPane.setParagraphAttributes( sas, false);

        myTextPane.repaint();      }
    });

    justifyButton.addActionListener( new ActionListener() {
      public void actionPerformed( ActionEvent e)
      {
        StyleConstants.setAlignment( sas, StyleConstants.ALIGN_JUSTIFIED);
        myTextPane.setParagraphAttributes( sas, false);

        myTextPane.repaint();
      }
    });

    buttonPanel.add( leftAlignButton);
    buttonPanel.add( centreButton);
    buttonPanel.add( rightAlignButton);
    buttonPanel.add( justifyButton);

    getContentPane().add( buttonPanel);
  }

  public static void main( String args[])
  {
    TestAlignment myFrame = new TestAlignment();
    myFrame.setVisible (true);
  }
}