Article View: borland.public.jbuilder.java.swing
Article #9717Print JTextComponent Problem
From: Laurent Kubanski
Date: Tue, 08 Feb 2000 00:00
Date: Tue, 08 Feb 2000 00:00
101 lines
3624 bytes
3624 bytes
Hi,
Printed a JTextComponent problem with the scaling of fonts.
You can see this bug with the java source code enclosed.
Thanks for your help.
Best Regards-
Laurent
JAVA SOURCE CODE
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
public class MyFrame extends JFrame implements ActionListener
{
public JTextPane myTextPane;
public MyFrame()
{
super("MyFrame");
getContentPane().setLayout(new BorderLayout());
myTextPane = new JTextPane();
String myString = "Line with key
tab.........................................................................
................" + '\t' + "123";
myString += '\n';
myString += "Line without key
tab.........................................................................
.......... 123 ";
myTextPane.setText(myString);
myTextPane.selectAll();
MutableAttributeSet myMutableAttributeSet = new
SimpleAttributeSet();
StyleConstants.setFontFamily(myMutableAttributeSet, "dialog");
myTextPane.setCharacterAttributes(myMutableAttributeSet, true);
myTextPane.select(0,0);
getContentPane().add(BorderLayout.CENTER, new
JScrollPane(myTextPane));
JPanel myPanel = new JPanel(new FlowLayout());
getContentPane().add(BorderLayout.SOUTH, myPanel);
Button myPrintButton = new Button("PRINT");
myPrintButton.addActionListener(this);
myPrintButton.setActionCommand("PRINT");
myPanel.add(myPrintButton);
Button myRefreshButton = new Button("REFRESH & PRINT");
myRefreshButton.addActionListener(this);
myRefreshButton.setActionCommand("REFRESH");
myPanel.add(myRefreshButton);
setBounds(20, 20, 500, 300);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if (e.getActionCommand().equals("PRINT")) {print();}
else if (e.getActionCommand().equals("REFRESH")) {refresh();}
}
public void print()
{
PrintJob myPrintJob = getToolkit().getPrintJob(this, null, null);
if (myPrintJob != null)
{
Graphics myGraphics = myPrintJob.getGraphics();
myGraphics.translate(50, 50);
myGraphics.setClip(myGraphics.getClip());
myTextPane.print(myGraphics);
myGraphics.dispose();
myPrintJob.end();
}
}
public void refresh()
{
for (int i=0; i<myTextPane.getText().length(); i++)
System.out.println("refresh : " + i);
myTextPane.select(i, i+1);
AttributeSet myAttributeSet =
myTextPane.getCharacterAttributes();
myTextPane.setCharacterAttributes(myAttributeSet, true);
}
myTextPane.select(0,0);
print();
}
public static void main(String arg[])
new MyFrame();
}
}
Technical Details
Message-ID:
<87oos7$u2g$1@minus.oleane.net>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,e7a892ada5a0496c,start X-Google-Attributes: gid111d45,public From: "Laurent Kubanski" <lkubanski@quartz-system.fr> Subject: Print JTextComponent Problem Date: 2000/02/08 Message-ID: <87oos7$u2g$1@minus.oleane.net> X-Deja-AN: 583138164 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3612.1700 X-Complaints-To: abuse@oleane.net X-Trace: minus.oleane.net 950003399 30800 62.160.166.95 (8 Feb 2000 09:49:59 GMT) Organization: Guest of OLEANE NNTP-Posting-Date: 8 Feb 2000 09:49:59 GMT Newsgroups: borland.public.jbuilder.java.swing