Hallo an alle.
ich habe folgende Fragen bzgl. setText mit einen HTML String :
Der Hintergrund ist, daß ich möchte, daß der Textsich auch über mehrere Zeilen erstrecken kann.
ich habe folgende Fragen bzgl. setText mit einen HTML String :
Der Hintergrund ist, daß ich möchte, daß der Textsich auch über mehrere Zeilen erstrecken kann.
- Wie wird die Farbe bei Button 8 bzw. 9 ermittelt ? Beim Button 8 und 9 habe ich für den Text HTML übergeben und den Button 8 disabled. Mir ist nicht klar, warum hier verschiedene Farben für den Text verwendet werden ?
- Wenn ich die Schriftgröße bei den Buttons ändern möchte, müsste ich dann den getFont() && deriveFont(style, size) verwenden ? Bzgl. müsste ich für B8 und B9 den HTML String neu setzen ?
Java:
import java.awt.*;
import javax.swing.*;
public class ButtonWithHTMLText extends JFrame {
JToggleButton b3 = new JToggleButton("T1");
JToggleButton b4 = new JToggleButton("T2");
JToggleButton b8 = new JToggleButton("<html>T3 diabled</html>");
JToggleButton b9 = new JToggleButton("<html>T4 enabled</html>");
ButtonWithHTMLText() {
this.setLayout(new GridBagLayout());
b4.setBackground(Color.WHITE);
b4.setEnabled(false);
b4.setBackground(Color.WHITE);
b3.setText("Hallo TW1");
b8.setEnabled(false);
this.setLayout(new GridBagLayout());
GridBagConstraints con3 = new GridBagConstraints() ;
con3.gridx=0;
con3.gridy = 0 ;
con3.weightx = 1 ;
con3.weighty = 1 ;
con3.fill = GridBagConstraints.BOTH ;
this.setLayout(new GridBagLayout());
GridBagConstraints con4 = new GridBagConstraints() ;
con4.gridx=0;
con4.gridy = 1 ;
con4.weightx = 1 ;
con4.weighty = 1 ;
con4.fill = GridBagConstraints.BOTH ;
GridBagConstraints con8 = new GridBagConstraints() ;
con8.gridx=0;
con8.gridy = 2 ;
con8.fill = GridBagConstraints.BOTH ;
con8.weightx = 1 ;
con8.weighty = 1 ;
GridBagConstraints con9 = new GridBagConstraints() ;
con9.gridx=0;
con9.gridy = 3 ;
con9.weightx = 1 ;
con9.weighty = 1 ;
con9.fill = GridBagConstraints.BOTH ;
this.add(b3, con3);
this.add(b4, con4);
this.add(b8, con8);
this.add(b9, con9);
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
ButtonWithHTMLText tmp = new ButtonWithHTMLText();
tmp.pack();
tmp.setVisible(true);
}
}