本文整理汇总了Java中javax.swing.JEditorPane.setBounds方法的典型用法代码示例。如果您正苦于以下问题:Java JEditorPane.setBounds方法的具体用法?Java JEditorPane.setBounds怎么用?Java JEditorPane.setBounds使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JEditorPane
的用法示例。
在下文中一共展示了JEditorPane.setBounds方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: JFileChooserExample
import javax.swing.JEditorPane; //导入方法依赖的package包/类
public JFileChooserExample() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
final JEditorPane editorPane = new JEditorPane();
editorPane.setBounds(20, 50, 387, 187);
contentPane.add(editorPane);
JButton btnNewButton = new JButton("Open File");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFileChooser fileopen = new JFileChooser();
FileFilter filter = new FileNameExtensionFilter("txt files", "txt");
fileopen.addChoosableFileFilter(filter);
int answer = fileopen.showDialog(null, "Open file");
if (answer == JFileChooser.APPROVE_OPTION) {
File file = fileopen.getSelectedFile();
try {
editorPane.setPage("File:///" + file);
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
});
btnNewButton.setBounds(10, 11, 89, 23);
contentPane.add(btnNewButton);
}
示例2: paintToPDF
import javax.swing.JEditorPane; //导入方法依赖的package包/类
public void paintToPDF(JEditorPane jep,File file) {
try {
jep.setBounds(0, 0, (int) convertToPixels(612 - 58), (int) convertToPixels(792 - 60));
Document document = new Document();
FileOutputStream fos = new FileOutputStream(file);
PdfWriter writer = PdfWriter.getInstance(document, fos);
document.setPageSize(new com.lowagie.text.Rectangle(612, 792));
document.open();
PdfContentByte cb = writer.getDirectContent();
cb.saveState();
cb.concatCTM(1, 0, 0, 1, 0, 0);
DefaultFontMapper mapper = new DefaultFontMapper();
mapper.insertDirectory("c:/windows/fonts");
Graphics2D g2 = cb.createGraphics(612, 792, mapper, true, .95f);
AffineTransform at = new AffineTransform();
at.translate(convertToPixels(20), convertToPixels(20));
at.scale(pixelToPoint, pixelToPoint);
g2.transform(at);
g2.setColor(Color.WHITE);
g2.fill(jep.getBounds());
Rectangle alloc = getVisibleEditorRect(jep);
jep.getUI().getRootView(jep).paint(g2, alloc);
g2.setColor(Color.BLACK);
g2.draw(jep.getBounds());
g2.dispose();
cb.restoreState();
document.close();
fos.flush();
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}