📄 descriptionpanel.java~3~
字号:
package p1;
import javax.swing.JPanel;
class DescriptionPanel extends JPanel
{
// Label for displaying an image icon
private JLabel jlblImage = new JLabel();
// Label for displaying a title
private JLabel jlblTitle = new JLabel();
// Text area for displaying text
private JTextArea jtaTextDescription;
// Default constructor
public DescriptionPanel()
{
// Group image label and title label in a panel
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.add(jlblImage, BorderLayout.CENTER);
panel.add(jlblTitle, BorderLayout.SOUTH);
// Create a scroll pane to hold text area
JScrollPane scrollPane = new JScrollPane
(jtaTextDescription = new JTextArea());
// Center the title on the label
jlblTitle.setHorizontalAlignment(JLabel.CENTER);
// Set the font for the title and text
jlblTitle.setFont(new Font("SansSerif", Font.BOLD, 16));
jtaTextDescription.setFont(new Font("Serif", Font.PLAIN, 14));
// Set lineWrap and wrapStyleWord true for text area
jtaTextDescription.setLineWrap(true);
jtaTextDescription.setWrapStyleWord(true);
// Set preferred size for the class class cscroll pane
scrollPane.setPreferredSize(new Dimension(200, 100));
// Set BorderLayout for the whole panel, add panel and scrollpane
setLayout(new BorderLayout());
add(scrollPane, BorderLayout.CENTER);
add(panel, BorderLayout.WEST);
}
// Set the title
public void setTitle(String title)
{
jlblTitle.setText(title);
}
// Set the image icon
public void setImageIcon(ImageIcon icon)
{
jlblImage.setIcon(icon);
Dimension dimension = new Dimension(icon.getIconWidth(),
icon.getIconHeight());
jlblImage.setPreferredSize(dimension);
}
// Set the text description
public void setTextDescription(String text)
{
jtaTextDescription.setText(text);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -