how to create own file with icon that inherit from JFrame icon, that I set it, in java and my own file use FileOutputStream and ObjectOutputStream(如何使用从 JFrame 图标继承的图标创建自己的文件,我设置它,在 java 和我自己的文件中使用 FileOutputStream 和 ObjectOutputStream) - IT屋-程序
问题描述
我想用继承自 JFrame 图标的图标创建我自己的文件,我在 java 中设置它,我自己的文件使用 FileOutputStream 和 ObjectOutputStream
I want to create my own file with icon that inherit from JFrame icon, that I set it, in java and my own file use FileOutputStream and ObjectOutputStream
try {
ObjectOutputStream oos;
//I create own file with own extension in drive D:
FileOutputStream fos = new FileOutputStream("D:/myFile.ckl");
oos = new ObjectOutputStream(fos);
//Write Document in JTextPane to File
oos.writeObject(jTextPane.getStyledDocument());
oos.close();
fos.close();
} catch (Exception exp) {
JOptionPane.showMessageDialog(null, "" + exp.getStackTrace());
}
提前谢谢你
推荐答案
@David 说宿主平台拥有 JFrame
装饰是正确的,但您也许可以利用 JInternalFrame
图标,它们通常概括了平台的图标.例如,
@David is correct that the host platform owns the JFrame
decorations, but you may be able to leverage the JInternalFrame
icons, which typically recapitulate those of the platform. For example,
private static final Icon ICON = (Icon) UIManager.get("InternalFrame.closeIcon");
这里列举了其他装饰性默认值.
Other decorative defaults are enumerated here.
SSCCE:
import java.awt.EventQueue;
import java.awt.GridLayout;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.UIManager;
/** @see http://stackoverflow.com/a/10360374/230513 */
public class InternalFrameIcons extends JPanel {
public InternalFrameIcons() {
this.setLayout(new GridLayout(0, 1, 5, 5));
this.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
this.add(createLabel("InternalFrame.closeIcon"));
this.add(createLabel("InternalFrame.maximizeIcon"));
this.add(createLabel("InternalFrame.minimizeIcon"));
}
private JLabel createLabel(String name) {
Icon icon = (Icon) UIManager.get(name);
JLabel label = new JLabel(name, icon, JLabel.CENTER);
label.setHorizontalTextPosition(JLabel.CENTER);
label.setVerticalTextPosition(JLabel.BOTTOM);
return label;
}
private void display() {
JFrame f = new JFrame("InternalFrameIcons");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(this);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new InternalFrameIcons().display();
}
});
}
}
这篇关于如何使用从 JFrame 图标继承的图标创建自己的文件,我设置它,在 java 和我自己的文件中使用 FileOutputStream 和 ObjectOutputStream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用从 JFrame 图标继承的图标创建自己的文件,我设置它,在 java 和我自己的文件中使用 FileOutputStream 和 ObjectOutputStream


基础教程推荐
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01
- 如何强制对超级方法进行多态调用? 2022-01-01
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- 在螺旋中写一个字符串 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01