Java - libro con varias paginas..

 
Vista:
sin imagen de perfil

libro con varias paginas..

Publicado por carlos (2 intervenciones) el 22/04/2015 20:02:26
lo que pretendo hacer es leer un archivo txt de un monton de lineas y llevarlo a un frame o ventana en javas
mi problema es que al leerlo en el Jtextarea ufff se me peta porque hay mucho texto y me an hablado que puedo solucionarlo con " t_are.getPreferredSize().getHeight();" que es mi valor inicial , y esto es mi valor final del txtarea t_are.getHeight(); pero no puedo ajustar el texto en toda la ventana porque readline me le cada linea uff y es dificil no lo consigo llevo varios dias en esto y estoy loko porque no consigo una solucion.. lo que pretendo hacer es leer el texto ..que se me ajuste al txtare todo el text y al pulsar el boton continuo leyendo la segunda pagina suena sencillo pero para mi es dificil alguien que me eche un cable gracias
este es el metodo donde leo el archivo .........
public void texto(JTextArea t_are, int fin) {
File archivo = new File("paraleer.txt");
FileReader leerArchivo = null;
BufferedReader bufferR = null;
if (archivo.exists()) {
try {
leerArchivo = new FileReader(archivo);
bufferR = new BufferedReader(leerArchivo);
fin = t_are.getHeight();
double inicio = t_are.getPreferredSize().getHeight();

String texto = bufferR.readLine();
StringBuilder ahora = new StringBuilder();
System.out.println(fin);
boolean sobrepasa = false;
while (texto != null) {

if (inicio <= fin) {

System.out.println(inicio + ".- " + texto);

ahora.append(texto);
}

texto = bufferR.readLine();
inicio = t_are.getPreferredSize().getHeight();

}
t_are.setText(String.valueOf(ahora));
} catch (FileNotFoundException e) {
} catch (IOException e) {
}

}
}
///////////////////////////////////////////////////////////////////este es mi frame//////////////////////////////////////////////////////////////////////


public class ventana2 {
E_04textodo texto1 = new E_04textodo();
E05Text0While text2=new E05Text0While();
E06_PruebaLonguitud texto3=new E06_PruebaLonguitud();
private JFrame frame;

/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
ventana2 window = new ventana2();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}

/**
* Create the application.
*/
public ventana2() {
initialize();
}

/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 260, 406);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JPanel panel = new JPanel();
frame.getContentPane().add(panel, BorderLayout.CENTER);
panel.setLayout(new GridLayout(0, 1, 0, 0));
// //////////////// txtarea texto///////////////
JTextArea TxTmultiple = new JTextArea();
TxTmultiple.setFont(new Font("MS PGothic", Font.BOLD, 18));
TxTmultiple.setText("");
panel.add(TxTmultiple);
// Se da cuenta que se a ido al borde y pasa a la siguente linea
TxTmultiple.setLineWrap(true);
// Detecta si es una palabra o o no
TxTmultiple.setWrapStyleWord(false);
// System.out.println(TxTmultiple.getFont().getSize());

JPanel panel_1 = new JPanel();
frame.getContentPane().add(panel_1, BorderLayout.SOUTH);
// /////////////////// comienza botton
JButton btnNewButton_1 = new JButton("marca");// //////// boton marcaa
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {

}
});
panel_1.add(btnNewButton_1);

JButton btnNewButton = new JButton("adelantee");// /boton Adenlatar
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
JTextArea t_are = TxTmultiple;
int fin = 0;
//texto1.texto(t_are, fin);
text2.texto(t_are, fin);
//texto3.texto(t_are, fin);

}
});
panel_1.add(btnNewButton);// final
}

}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder