我正在尝试将特定的jInternalFrame
保存为文件作为图片。内部框架位于jFrame
的{{1}}中的jTabbedPane
。读数很好,除了内部框架的50%。它不希望显示其余的读数,因此没有错误。我想扩大图像的视图......任何人都可以帮助我吗?
以下是通过点击监听器激活的方法:
jTabbedPane
答案 0 :(得分:2)
不要使用paintComponents(
)绘画使用paintComponent()
不要直接使用JInternalFrame将背景描绘到paintComponent()
放置JPanel或JComponent
如果您只想显示图片,请将图片加载为Icon
使用CardLayout代替JInternalFrames
使用SSCCE
答案 1 :(得分:0)
非常感谢你的想法...给了我解决问题所需的一切帮助..我发现这些代码有些多余,但我仍会发布。
private void tallennus(){
JPanel drawingPanel = new JPanel();
drawingPanel.setSize(new Dimension((int)PageSize.A4.getWidth(),(int)PageSize.A4.getHeight()));
jPanel11.setBackground(Color.WHITE);
jScrollPane27.setBackground(Color.WHITE);
jPanel11.setBackground(Color.WHITE);
jTabbedPane1.setBackground(Color.WHITE);
jPanel10.setBackground(Color.WHITE);
drawingPanel.setBackground(Color.WHITE);
drawingPanel.setForeground(Color.WHITE);
add(drawingPanel);
Container cont = jInternalFrame1;
jInternalFrame1.pack();
String Ifra = jInternalFrame1.getComponents().toString();
BufferedImage sama = (BufferedImage) cont.createImage((int)PageSize.A4.getWidth(),(int)PageSize.A4.getHeight()+(int)PageSize.A4.getHeight());
drawingPanel.add(cont);
setContentPane(drawingPanel);
this.pack();
Dimension size = drawingPanel.getSize();
BufferedImage image = new BufferedImage(size.width, (int)PageSize.A4.getHeight()+400,
BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = image.createGraphics();
g2.setBackground(Color.WHITE);
g2.clearRect(0,0,size.width,(int)PageSize.A4.getHeight() + 400);
g2.clipRect(40, 90, 1200, 1450);
g2.drawString(Ifra, TOP_ALIGNMENT, TOP_ALIGNMENT);
g2.drawImage(sama, null, cont);
g2.clipRect(40, 90, 1200, 1450);
this.pack();
paint(g2);
try{
ImageIO.write(image,"jpeg",new File("snap.jpg"));
}
catch(Exception e){}
}