federico100mt
20-03-2009, 12:51
ciao a tutti, ho un mistero per le mani, perchè quando uso questo codice non mi fa quello che dico io??? :D
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
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);
}
}
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
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);
}
}