随便写写——JFrame中加载JPanel,JLabel中字符串换行显示
来源:互联网 发布:软件开发流程图工具 编辑:程序博客网 时间:2024/06/05 21:54
public class JPanelJFrame extends JFrame {
HelpPanel panel = new HelpPanel();
public JPanelJFrame() {
this.setLayout(new BorderLayout());
this.getContentPane().add(panel);
this.setSize(panel.getWidth() + 10, panel.getHeight() + 10);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public static void main(String[] args) {
new JPanelJFrame();
}
}
public class HelpPanel extends JPanel {
private JLabel loadMIBLabel;
private JLabel loadMIBPicLabel;
private JLabel loadDataLabel;
private JLabel loadDataPicLabel;
private int w_width;
private int h_height;
private int maxWidth;
private String picPath = "images/splash.jpg";
public HelpPanel() {
initGUI();
}
private void initGUI() {
try {
{
GridBagLayout thisLayout = new GridBagLayout();
thisLayout.rowWeights = new double[] {0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1};
thisLayout.rowHeights = new int[] {7, 7, 7, 7, 7, 7, 7, 7};
thisLayout.columnWeights = new double[] {0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1};
thisLayout.columnWidths = new int[] {7, 7, 7, 7, 7, 7, 7, 7};
this.setLayout(thisLayout);
{
loadMIBLabel = new JLabel("<html>加载文件的步骤是:<br> 1.选择'文件'菜单,然后选择'加载文件'菜单项 <br>2.在弹出的'加载文件对话框'中,输入文件的绝对路径,或者点击'浏览'按钮,选择文件</html>", SwingConstants.CENTER);
this.add(loadMIBLabel, new GridBagConstraints(0, 0, 8, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(6, 12, 6, 12), 0, 0));
// loadMIBLabel.setHorizontalTextPosition(JLabel.CENTER);
System.out.println(loadMIBLabel.getWidth());
maxWidth = maxWidth > loadMIBLabel.getWidth() ? maxWidth : loadMIBLabel.getWidth();
h_height += 100;
}
{
ImageIcon imageIcon = new ImageIcon(picPath);
Image image = imageIcon.getImage();
int width = image.getWidth(null);
int height = image.getHeight(null);
loadMIBPicLabel = new JLabel(imageIcon);
this.add(loadMIBPicLabel, new GridBagConstraints(0, 1, 8, 3, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(6, 12, 6, 12), 0, 0));
// loadMIBPicLabel.setText("<html>步骤是:<br> 1.打开菜单 <br>2.选择文件</html>");
maxWidth = maxWidth > width ? maxWidth : width;
h_height += height;
}
{
loadDataLabel = new JLabel();
this.add(loadDataLabel, new GridBagConstraints(0, 4, 8, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(6, 12, 6, 12), 0, 0));
loadDataLabel.setText("<html>步骤是:<br> 1.打开菜单 <br>2.选择文件</html>");
maxWidth = maxWidth > loadDataLabel.getWidth() ? maxWidth : loadDataLabel.getWidth();
h_height += 100;
}
{
ImageIcon imageIcon = new ImageIcon(picPath);
Image image = imageIcon.getImage();
int width = image.getWidth(null);
int height = image.getHeight(null);
loadDataPicLabel = new JLabel(imageIcon);
this.add(loadDataPicLabel, new GridBagConstraints(0, 5, 8, 3, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(6, 12, 6, 12), 0, 0));
// loadDataPicLabel.setText("<html>步骤是:<br> 1.打开菜单 <br>2.选择文件</html>");
maxWidth = maxWidth > width ? maxWidth : width;
h_height += height;
}
{
this.w_width = maxWidth;
this.setSize(this.w_width, h_height);
System.out.println(this.w_width + " " + this.h_height);
}
}
} catch(Exception e) {
e.printStackTrace();
}
}
}
- 随便写写——JFrame中加载JPanel,JLabel中字符串换行显示
- JFrame,JPanel,JLabel详解
- JFrame,JPanel,JLabel学习
- java的JLabel中显示的文字换行
- 在JFrame中设置JPanel的值
- 让JLabel换行显示
- JLabel, JButton换行显示
- JDialog中加载若干JPanel
- JFrame(框架)中添加和设置JPanel(面板)的方法
- java swing中jpanel跟jframe的区别
- javax.swing.JFrame中使用jpanel来布局
- JFrame(框架)中添加和设置JPanel(面板)的方法
- javax.swing.JFrame中使用jpanel来布局
- JFrame(框架)中添加和设置JPanel(面板)的方法
- JFrame(框架)中添加和设置JPanel(面板)的方法
- JFrame(框架)中添加和设置JPanel(面板
- JAVA 基本绘图——利用JFrame JPanel 绘制扇形
- java中jframe 和jpanel的区别 (java的swing界面)
- WinCE6/PXA310/TCPMP播放视频xscale硬件加速修改
- 修改hosts文件
- 成功离我有多远
- 在Ubuntu下安装tokyocabinet数据库
- 成功搭建了iphone app开发环境
- 随便写写——JFrame中加载JPanel,JLabel中字符串换行显示
- Android 之菜单
- Timer类中两个schedule方法使用的注意事项
- uboot_2010.3移植记录0
- ie9 flash 播放不了 解决方法 笔记
- XP清除用户密码
- MFC一天一练 ---- 基本的文本操作
- javascript的闭包(转自CSDN)
- maven2的主要配置pom.xml