Java tutorial
//package com.java2s; import javax.swing.*; import javax.swing.border.EmptyBorder; import javax.swing.text.JTextComponent; import java.awt.*; public class Main { public static final Color DEFAULT_COLOR = new Color(0x99, 0xFF, 0xCC); public static final Font DEFAULT_FONT = new Font(Font.MONOSPACED, Font.PLAIN, 14); public static JPanel createVTextComponentPane(String labelText, JTextComponent textComp) { return createTextComponentPane(labelText, textComp, DEFAULT_FONT, DEFAULT_COLOR, true); } public static JPanel createTextComponentPane(String labelText, JTextComponent textComp, Font font, Color bgColor, boolean isVertical) { JPanel outPane = new JPanel(); outPane.setLayout(new BorderLayout()); outPane.setBorder(new EmptyBorder(5, 5, 5, 5)); JLabel labelOut = new JLabel(labelText, SwingConstants.LEFT); if (isVertical) { outPane.add(labelOut, BorderLayout.NORTH); } else { outPane.add(labelOut, BorderLayout.WEST); } if (textComp instanceof JTextArea) { outPane.add(createScrollPane((JTextArea) textComp, font, bgColor), BorderLayout.CENTER); } else { textComp.setBackground(bgColor); textComp.setFont(font); outPane.add(textComp, BorderLayout.CENTER); } return outPane; } public static JScrollPane createScrollPane(JTextArea textArea, Font font, Color bgColor) { JScrollPane scrollPane = new JScrollPane(textArea); textArea.setLineWrap(true); textArea.setWrapStyleWord(true); if (null != font) { textArea.setFont(font); } textArea.setOpaque(true); if (bgColor != null) { textArea.setBackground(bgColor); } return scrollPane; } public static void setFont(Font f) { // Font f = new Font("Tahoma",Font.PLAIN,11); UIManager.put("TextField.font", f); UIManager.put("TextArea.font", f); UIManager.put("Label.font", f); UIManager.put("ComboBox.font", f); UIManager.put("MenuBar.font", f); UIManager.put("Menu.font", f); UIManager.put("ToolTip.font", f); UIManager.put("MenuItem.font", f); UIManager.put("List.font", f); UIManager.put("Button.font", f); UIManager.put("Table.font", f); } }