Home / ພື້ນຖານ Desktop app / GUI_Component / GUI_Template
public class MyForm extends JFrame {
public MyForm() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 362, 249);
setTitle("Kittisay Java");
getContentPane().setLayout(null);
JTextPane textPane = new JTextPane();
textPane.setText("\nString Of Line 1");
textPane.setBounds(78, 34, 114, 137);
StyledDocument doc = textPane.getStyledDocument();
// Define a style1
SimpleAttributeSet style1 = new SimpleAttributeSet();
StyleConstants.setForeground(style1, Color.RED);
StyleConstants.setBackground(style1, Color.YELLOW);
StyleConstants.setBold(style1, true);
SimpleAttributeSet style2 = new SimpleAttributeSet();
StyleConstants.setForeground(style2, Color.GREEN);
// Add some text
try {
doc.insertString(doc.getLength(), "\nString Of Line 2", null);
doc.insertString(doc.getLength(), "\nString Of Line 3", style1);
doc.insertString(doc.getLength(), "\nString Of Line 4", style2);
doc.insertString(doc.getLength(), "\n", null);
} catch (Exception e) {
System.out.println(e);
}
textPane.insertIcon(new ImageIcon(getClass().getResource("icons.png")));
add(textPane);
}
public static void main(String[] args) {
MyForm frm = new MyForm();
frm.setVisible(true);
}