java – 在JLabel Icon上添加JLabel文本.使用相同的JLabel文本
发布时间:2020-12-15 04:42:33 所属栏目:Java 来源:网络整理
导读:抱歉标题含糊不清但我想不出我想在标题中做什么. 无论如何,对于文本覆盖图像,我使用了JLabel文本并将其添加到Icon中. JLabel icon = new JLabel(new ImageIcon); icon.setLayout(new GridBagLayout()); add(icon); JLabel text = new JLabel(); text.setText
抱歉标题含糊不清但我想不出我想在标题中做什么.
无论如何,对于文本覆盖图像,我使用了JLabel文本并将其添加到Icon中. JLabel icon = new JLabel(new ImageIcon); icon.setLayout(new GridBagLayout()); add(icon); JLabel text = new JLabel(); text.setText(language.getString("translation")); text.setLocation(10,10); text.setSize(text.getPreferredSize()); icon.add(text); 我正在为我的应用程序做i18n,每次切换区域设置时,它都会将相同的JLabel添加到上一个,这样您就可以看到彼此重叠的文本了.如何使用相同的Jlabel而不是在顶部添加新的Jlabel? 谢谢 解决方法
我想你要创建的是带有自定义图标的JLabel
你应该创建一个JLabel并设置它的图标,如下所示: JLabel label = new JLabel(language.getString("translation")); label.setIcon(new ImageIcon(/* path of your icon */)); 如果要修复文本重叠,则应设置文本对齐方式 lblText.setHorizo??ntalTextPosition(JLabel.CENTER); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |