1  import javax.swing.*;
  2  import java.awt.*;
  3  
  4  public class DescriptionPanel extends JPanel {
  5    /** Label for displaying an image icon and a title */
  6    private JLabel jlblImageTitle = new JLabel();
  7  
  8    /** Text area for displaying text */
  9    private JTextArea jtaDescription = new JTextArea();
 10  
 11    public DescriptionPanel() {
 12      // Center the icon and text and place the text under the icon
 13      jlblImageTitle.setHorizontalAlignment(JLabel.CENTER);
 14      jlblImageTitle.setHorizontalTextPosition(JLabel.CENTER);
 15      jlblImageTitle.setVerticalTextPosition(JLabel.BOTTOM);
 16  
 17      // Set the font in the label and the text field
 18      jlblImageTitle.setFont(new Font("SansSerif", Font.BOLD, 16));
 19      jtaDescription.setFont(new Font("Serif", Font.PLAIN, 14));
 20  
 21      // Set lineWrap and wrapStyleWord true for the text area
 22      jtaDescription.setLineWrap(true);
 23      jtaDescription.setWrapStyleWord(true);
 24      jtaDescription.setEditable(false);
 25  
 26      // Create a scroll pane to hold the text area
 27      JScrollPane scrollPane = new JScrollPane(jtaDescription);
 28  
 29      // Set BorderLayout for the panel, add label and scrollpane
 30      setLayout(new BorderLayout(5, 5));
 31      add(scrollPane, BorderLayout.CENTER);
 32      add(jlblImageTitle, BorderLayout.WEST);
 33    }
 34  
 35    /** Set the title */
 36    public void setTitle(String title) {
 37      jlblImageTitle.setText(title);
 38    }
 39  
 40    /** Set the image icon */
 41    public void setImageIcon(ImageIcon icon) {
 42      jlblImageTitle.setIcon(icon);
 43    }
 44  
 45    /** Set the text description */
 46    public void setDescription(String text) {
 47      jtaDescription.setText(text);
 48    }
 49  }