Java Code Examples for javax.swing.JEditorPane#setPreferredSize()

The following examples show how to use javax.swing.JEditorPane#setPreferredSize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PropertiesCustomEditor.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** This method is called from within the constructor to
 * initialize the form.
 */
private void initComponents() {
    setLayout(new BorderLayout());
    
    editorPane = new JEditorPane();
    editorPane.setContentType("text/x-properties"); // NOI18N
    // XXX pretty arbitrary! No way to set by rows & columns??
    editorPane.setPreferredSize(new Dimension(200, 100));
    add(new JScrollPane(editorPane), BorderLayout.CENTER);

    warnings = new JTextField(30);
    warnings.setEditable(false);
    add(warnings, BorderLayout.SOUTH);
}
 
Example 2
Source File: BrowserDialog.java    From sc2gears with Apache License 2.0 5 votes vote down vote up
/**
 * Completes the initialization of the dialog.
 * @param url           URL of the page to be displayed
 * @param preferredSize optional preferred size of the browser component
 */
private void completeInit( final String url, final Dimension preferredSize ) {
	final JEditorPane browserPane = GuiUtils.createEditorPane();
	browserPane.setPreferredSize( preferredSize );
	final JScrollPane scrollPane = new JScrollPane( browserPane );
	scrollPane.setBorder( BorderFactory.createEmptyBorder( 10, 10, 10, 10 ) );
	getContentPane().add( scrollPane, BorderLayout.CENTER );
	
	final JButton okButton = createCloseButton( "button.close" );
	getContentPane().add( GuiUtils.wrapInPanel( okButton ), BorderLayout.SOUTH );
	
	// Load page content in a new thread to not block the AWT event dispatcher thread
	new NormalThread( "Browser dialog content loader" ) {
		@Override
           public void run() {
			try {
				browserPane.setCursor( Cursor.getPredefinedCursor( Cursor.WAIT_CURSOR ) );
		        browserPane.setPage( url );
	        } catch ( final IOException ie ) {
		        ie.printStackTrace();
		        browserPane.setContentType( "text/html" );
		        browserPane.setText( "<html><body style='font-family:arial;font-size:10px;font-style:italic;background:#ffffff;'>"
						+ "<p>This content is currently unavailable. Please try again later.</p></body></html>" );
	        } finally {
				browserPane.setCursor( null );
	        }
           }
	}.start();
	
	packAndShow( okButton, false );
}
 
Example 3
Source File: ClassMemberPanel.java    From jeddict with Apache License 2.0 5 votes vote down vote up
private String getCode(String code, String title) {
    JEditorPane editorPane = new JEditorPane();
    editorPane.setContentType("text/x-java");
    editorPane.setPreferredSize(new java.awt.Dimension(600, 400));
    editorPane.setText(code);
    OptionDialog dialog = new OptionDialog(editorPane, title);
    dialog.setVisible(true);
    if (OK_OPTION == dialog.getDialogResult()) {
        return editorPane.getText();
    } else {
        return code;
    }
}
 
Example 4
Source File: TransferMaskDialog.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private JComponent createHelpPanel() {
    JEditorPane helpPane = new JEditorPane("text/html", null);
    helpPane.setEditable(false);
    helpPane.setPreferredSize(new Dimension(400, 120));
    helpPane.setText("<html><body>Copying the <b>definition</b> of a mask means the mathematical expression " +
    		"is evaluated in the target product. This is only possible,  " +
    		"if the bands which are used in this expression are present in the target product.<br/> " +
    		"Copying the <b>pixel</b> means the data of the mask is transferred to the target product. " +
    		"This is only possible when both product overlap spatially.</body></html>");
    JScrollPane helpPanelScrollPane = new JScrollPane(helpPane);
    helpPanelScrollPane.setBorder(BorderFactory.createTitledBorder("Description"));
    return helpPanelScrollPane;
}
 
Example 5
Source File: CompoundDemoFrame.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected JComponent createDescriptionTextPane(final URL url)
{
  final JEditorPane editorPane = new JEditorPane();
  editorPane.setEditable(false);
  editorPane.setPreferredSize(new Dimension(400, 200));
  if (url != null)
  {
    try
    {
      editorPane.setPage(url);
    }
    catch (IOException e)
    {
      logger.error("Failed to load demo description", e);
      editorPane.setText("Unable to load the demo description. Error: " + e
          .getMessage());
    }
  }
  else
  {
    editorPane.setText(
        "Unable to load the demo description. No such resource.");
  }

  return new JScrollPane(editorPane,
      JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
      JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
}
 
Example 6
Source File: SimpleDemoFrame.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected JComponent createDefaultContentPane()
{
  final JPanel content = new JPanel(new BorderLayout());
  content.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));

  final InternalDemoHandler demoHandler = getDemoHandler();
  final JEditorPane editorPane = new JEditorPane();
  final URL url = demoHandler.getDemoDescriptionSource();
  editorPane.setEditable(false);
  editorPane.setPreferredSize(new Dimension(400, 200));
  if (url != null)
  {
    try
    {
      editorPane.setPage(url);
    }
    catch (IOException e)
    {
      editorPane.setText("Unable to load the demo description. Error: " + e.getMessage());
    }
  }
  else
  {
    editorPane.setText("Unable to load the demo description. No such resource.");
  }

  final JScrollPane scroll = new JScrollPane(editorPane,
      JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

  final JButton previewButton = new JButton(getPreviewAction());

  final JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
  splitPane.setTopComponent(scroll);
  splitPane.setBottomComponent(demoHandler.getPresentationComponent());
  content.add(splitPane, BorderLayout.CENTER);
  content.add(previewButton, BorderLayout.SOUTH);
  return content;
}
 
Example 7
Source File: frmReleaseNote.java    From Course_Generator with GNU General Public License v3.0 4 votes vote down vote up
private void initComponents() {

		setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
		setTitle(bundle.getString("frmReleaseNote.title")); // Release notes
		setAlwaysOnTop(true);

		// -- Layout
		// ------------------------------------------------------------
		Container paneGlobal = getContentPane();
		paneGlobal.setLayout(new GridBagLayout());

		editorStat = new JEditorPane();
		editorStat.setContentType("text/html");
		editorStat.setEditable(false);
		editorStat.setPreferredSize(new Dimension(600, 400));
		scrollPaneStat = new JScrollPane(editorStat);

		Utils.addComponent(paneGlobal, scrollPaneStat, 0, 0, 1, 1, 1, 1, 10, 10, 0, 10,
				GridBagConstraints.BASELINE_LEADING, GridBagConstraints.BOTH);

		chkDisable = new javax.swing.JCheckBox();
		chkDisable.setText(bundle.getString("frmReleaseNote.chkDisable.Text")); // Stop displaying this dialog box.
		Utils.addComponent(paneGlobal, chkDisable, 0, 1, 1, 1, 1, 0, 10, 10, 10, 10,
				GridBagConstraints.BASELINE_LEADING, GridBagConstraints.BOTH);

		// == BUTTONS
		// ===========================================================
		jPanelButtons = new javax.swing.JPanel();
		jPanelButtons.setLayout(new FlowLayout());
		Utils.addComponent(paneGlobal, jPanelButtons, 0, 2, GridBagConstraints.REMAINDER, 1, 0, 0, 0, 0, 0, 0,
				GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL);

		btClose = new javax.swing.JButton();
		btClose.setText(bundle.getString("frmReleaseNote.btClose.text")); // Close
		btClose.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				// -- Is the checkbox checked? Yes, set ReleaseNote to version in order to avoid
				// the display of the dialog at the next start
				if (chkDisable.isSelected()) {
					settings.ReleaseVersion = version;
				}
				setVisible(false);
			}
		});

		// -- Add buttons
		jPanelButtons.add(btClose);

		// --
		pack();
		setLocationRelativeTo(null);
	}
 
Example 8
Source File: UpdateProgressBar.java    From stendhal with GNU General Public License v2.0 4 votes vote down vote up
private void initializeComponents() {
	JPanel contentPane = (JPanel) this.getContentPane();

	contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS));
	contentPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

	if (fromVersion == null) {
		contentPane.add(new JLabel("Please wait while " + ClientGameConfiguration.get("GAME_NAME") + " is downloaded..."));
	} else {
		contentPane.add(new JLabel("Downloading updates..."));
	}
	contentPane.add(Box.createVerticalStrut(5));

	progressBar = new JProgressBar(0, max);
	progressBar.setStringPainted(false);
	progressBar.setValue(0);
	contentPane.add(progressBar);
	contentPane.add(Box.createVerticalStrut(5));

	if (urlBase != null) {
		// Set up page display.
		browser = new JEditorPane();
		browser.setContentType("text/html");
		browser.setEditable(false);
		Dimension dim = new Dimension(600, 440);
		browser.setPreferredSize(dim);
		browser.addPropertyChangeListener("page", new UpdateProgressBarMetaRefreshSupport());
		browser.addHyperlinkListener(new UpdateProgressBarHyperLinkListener());

		Dimension windowSize = new Dimension(640, 480);
		setPreferredSize(windowSize);
		// TODO: load page async?
		try {
			browser.setPage(urlBase + fromVersion + "/" + toVersion + ".html");
		} catch (IOException e) {
			System.out.println(e);
		}

		// Gige the page scroll bars if it needs them
		final JScrollPane scrollPane = new JScrollPane(browser);
		contentPane.add(scrollPane);
	}
}
 
Example 9
Source File: ArtARDemo.java    From COMP3204 with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public JPanel getComponent(int width, int height) throws IOException {
	final JPanel container = new JPanel();
	container.setSize(width, height);
	container.setPreferredSize(container.getSize());

	final OverlayLayout overlay = new OverlayLayout(container);
	container.setLayout(overlay);

	labelField = new JEditorPane();
	labelField.setOpaque(false);
	labelField.setSize(640 - 50, 480 - 50);
	labelField.setPreferredSize(labelField.getSize());
	labelField.setMaximumSize(labelField.getSize());
	labelField.setContentType("text/html");

	// add a HTMLEditorKit to the editor pane
	final HTMLEditorKit kit = new HTMLEditorKit();
	labelField.setEditorKit(kit);

	final StyleSheet styleSheet = kit.getStyleSheet();
	styleSheet.addRule("body {color:#FF00FF; font-family:courier;}");
	styleSheet.addRule("h1 {font-size: 60pt}");
	styleSheet.addRule("h2 {font-size: 50pt }");

	final Document doc = kit.createDefaultDocument();
	labelField.setDocument(doc);

	// final GridBagConstraints gbc = new GridBagConstraints();
	// gbc.gridy = 1;
	// panel.add(labelField, gbc);
	container.add(labelField);
	// labelField.setAlignmentX(0.5f);
	// labelField.setAlignmentY(0.5f);

	final JPanel panel = super.getComponent(width, height);
	container.add(panel);

	vc.getDisplay().addVideoListener(this);

	isRunning = true;
	new Thread(this).start();

	return container;
}
 
Example 10
Source File: CheckForUpdateAction.java    From nextreports-designer with Apache License 2.0 4 votes vote down vote up
private JComponent createPanel(String html) {
	System.setProperty("awt.useSystemAAFontSettings", "on");
	final JEditorPane editorPane = new JEditorPane();    	
	HTMLEditorKit kit = new HTMLEditorKit();
	editorPane.setEditorKit(kit);
    editorPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
    editorPane.setFont(new Font("Arial", Font.PLAIN, 12));
    editorPane.setPreferredSize(new Dimension(350, 120));
    editorPane.setEditable(false);
    editorPane.setContentType("text/html");
    editorPane.setBackground(new Color(234, 241, 248));        
   
    Document doc = kit.createDefaultDocument();
    editorPane.setDocument(doc);
    editorPane.setText(html);

    // Add Hyperlink listener to process hyperlinks
    editorPane.addHyperlinkListener(new HyperlinkListener() {
        public void hyperlinkUpdate(final HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ENTERED) {
                EventQueue.invokeLater(new Runnable() {
                    public void run() {
                        SwingUtilities.getWindowAncestor(editorPane).setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
                        editorPane.setToolTipText(e.getURL().toExternalForm());
                    }
                });
            } else if (e.getEventType() == HyperlinkEvent.EventType.EXITED) {
                EventQueue.invokeLater(new Runnable() {
                    public void run() {                            
                        SwingUtilities.getWindowAncestor(editorPane).setCursor(Cursor.getDefaultCursor());
                        editorPane.setToolTipText(null);
                    }
                });
            } else if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {       
            	    FileUtil.openUrl(e.getURL().toString(), AboutAction.class);                       
            }
        }
    });        
    editorPane.addMouseListener(mouseListener);
    JScrollPane sp = new JScrollPane(editorPane);       
    return sp;
}