|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Member
Iscritto dal: Apr 2008
Messaggi: 86
|
[java] StyleContext Document perche stampa 4 volte??
ciao a tutti, ho un mistero per le mani, perchè quando uso questo codice non mi fa quello che dico io???
![]() cioé, io vorrei che per ogni JTabbedPane venga stampata una locazione del vettore di stringhe. Quindi solo la stringa corrente che gli passo, invece lui le stampa tutte. Purtroppo sono costretto a usare questo Document per formattarle. Conoscete un sistema differente per formattare una stringa in una TextArea??? ![]() grazie mille fede Codice:
public class AboutJmrui { StyleContext context = new StyleContext(); StyledDocument document = new DefaultStyledDocument(context); public String[] vect; public AboutJmrui(String[] s) { vect=s; } void add(JTabbedPane tabbedPane, String label, int i) { Style style = context.getStyle(StyleContext.DEFAULT_STYLE); StyleConstants.setAlignment(style, StyleConstants.ALIGN_LEFT); StyleConstants.setFontSize(style, 14); StyleConstants.setSpaceAbove(style, 4); StyleConstants.setSpaceBelow(style, 4); try { document.insertString(document.getLength(), vect[i], style); } catch (BadLocationException badLocationException) { System.err.println("Error"); } JTextPane textPane = new JTextPane(document); textPane.setEditable(false); tabbedPane.addTab(label, textPane); } public void AboutDialog() { JFrame frame = new JFrame("About JMRUI"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTabbedPane tabbedPane = new JTabbedPane(); String titles[] = { "Version", "Project", "License agreement", "Programmers"}; for (int i = 0, n = titles.length; i < n; i++) { add(tabbedPane, titles[i],i); } frame.add(tabbedPane, BorderLayout.CENTER); frame.setSize(400, 400); frame.setVisible(true); } } Ultima modifica di federico100mt : 20-03-2009 alle 12:55. |
![]() |
![]() |
![]() |
#2 | |
Senior Member
Iscritto dal: Oct 2006
Città: milano
Messaggi: 1439
|
Quote:
![]() |
|
![]() |
![]() |
![]() |
#3 |
Member
Iscritto dal: Apr 2008
Messaggi: 86
|
ok, ci sto, come posso fargli stampare solo la stringa corrente??
nel senso, mi piacerebbe, usando questo metodo, ma magari ce ne sono di piu veloci! grazie.. |
![]() |
![]() |
![]() |
#4 |
Senior Member
Iscritto dal: Oct 2006
Città: milano
Messaggi: 1439
|
|
![]() |
![]() |
![]() |
#5 |
Member
Iscritto dal: Apr 2008
Messaggi: 86
|
aaa!!! ok!!
anche una battuta puó aiutare! ![]() |
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 17:36.