當前位置: 首頁>>代碼示例>>Java>>正文


Java JEditorPane.setBounds方法代碼示例

本文整理匯總了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);
}
 
開發者ID:ozkansari,項目名稱:MyCourses,代碼行數:31,代碼來源:JFileChooserExample.java

示例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();
  }
}
 
開發者ID:ksaluja24,項目名稱:scratch-bench,代碼行數:45,代碼來源:MainMenu.java


注:本文中的javax.swing.JEditorPane.setBounds方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。