Java Code Examples for javax.swing.JTextPane#setPreferredSize()
The following examples show how to use
javax.swing.JTextPane#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: LocRecordsView.java From openvisualtraceroute with GNU Lesser General Public License v3.0 | 6 votes |
public LocRecordsView(final Window parent, final ServiceFactory factory) { super(parent, Resources.getLabel("LocRecords"), ModalityType.APPLICATION_MODAL); final String rawLocRecords = factory.getGeo().getLocRecordsStr(); final JTextPane text = new JTextPane(); text.setEditable(true); text.setText(rawLocRecords); text.setPreferredSize(new Dimension(800, 400)); getContentPane().add(text, BorderLayout.CENTER); final JButton save = new JButton("Save"); save.addActionListener(e -> { final Pair<String, Exception> error = factory.getGeo().parseAndLoadDNSRecords(text.getText()); text.setText(factory.getGeo().getLocRecordsStr()); if (StringUtils.isNotEmpty(error.getKey())) { JOptionPane.showMessageDialog(LocRecordsView.this, Resources.getLabel("dns.loc.warning", error.getKey()), Resources.getLabel("warning"), JOptionPane.WARNING_MESSAGE); } else { JOptionPane.showMessageDialog(LocRecordsView.this, Resources.getLabel("dns.loc.updated")); LocRecordsView.this.dispose(); } }); getContentPane().add(save, BorderLayout.SOUTH); pack(); setLocationRelativeTo(parent); setVisible(true); }
Example 2
Source File: LibraryUpdateCommand.java From gcs with Mozilla Public License 2.0 | 6 votes |
public static void askUserToUpdate(Library library, Release release) { JTextPane markdown = new JTextPane(new MarkdownDocument(I18n.Text("NOTE: Existing content for this library will be removed and replaced. Content in other libraries will not be modified.\n\n" + release.getNotes()))); Dimension size = markdown.getPreferredSize(); JScrollPane scroller = new JScrollPane(markdown); int maxWidth = Math.min(600, WindowUtils.getMaximumWindowBounds().width * 3 / 2); if (size.width > maxWidth) { markdown.setSize(new Dimension(maxWidth, Short.MAX_VALUE)); size = markdown.getPreferredSize(); size.width = maxWidth; markdown.setPreferredSize(size); } String update = I18n.Text("Update"); if (WindowUtils.showOptionDialog(null, scroller, String.format(I18n.Text("%s v%s is available!"), library.getTitle(), release.getVersion()), true, JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[]{update, I18n.Text("Ignore")}, update) == JOptionPane.OK_OPTION) { LibraryUpdater.download(library, release); } }
Example 3
Source File: DomGameFrame.java From DominionSim with MIT License | 6 votes |
private JPanel getLogPanel() { JPanel theLogPanel = new JPanel(); theLogPanel.setLayout(new BorderLayout()); myLogPane = new JTextPane(); myLogPane.setPreferredSize(new Dimension(400,300)); editorKit = new HTMLEditorKit(); gameLog = (HTMLDocument) editorKit.createDefaultDocument();; myLogPane.setEditorKit(editorKit); myLogPane.setDocument(gameLog); myLogScroll = new JScrollPane(myLogPane); myLogScroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); // theScrollPane.setPreferredSize(new Dimension(400,400)); theLogPanel.add(myLogScroll,BorderLayout.CENTER); Font font = new Font("Times New Roman", Font.PLAIN, 14); String bodyRule = "body { font-family: " + font.getFamily() + "; " + "font-size: " + font.getSize() + "pt; }"; ((HTMLDocument)myLogPane.getDocument()).getStyleSheet().addRule(bodyRule);// myLogPane.revalidate(); return theLogPanel; }
Example 4
Source File: UpdateChecker.java From gcs with Mozilla Public License 2.0 | 5 votes |
private void tryNotify() { if (GCS.isNotificationAllowed()) { String update = I18n.Text("Update"); mMode = Mode.DONE; if (isNewAppVersionAvailable()) { JTextPane markdown = new JTextPane(new MarkdownDocument(getAppReleaseNotes())); Dimension size = markdown.getPreferredSize(); JScrollPane scroller = new JScrollPane(markdown); int maxWidth = Math.min(600, WindowUtils.getMaximumWindowBounds().width * 3 / 2); if (size.width > maxWidth) { markdown.setSize(new Dimension(maxWidth, Short.MAX_VALUE)); size = markdown.getPreferredSize(); size.width = maxWidth; markdown.setPreferredSize(size); } if (WindowUtils.showOptionDialog(null, scroller, getAppResult(), true, JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[]{update, I18n.Text("Ignore")}, update) == JOptionPane.OK_OPTION) { goToUpdate(); } return; } for (Library lib : Library.LIBRARIES) { if (lib != Library.USER) { Release release = lib.getAvailableUpgrade(); if (release != null && !release.unableToAccessRepo() && release.hasUpdate() && !release.getVersion().equals(lib.getVersionOnDisk())) { LibraryUpdateCommand.askUserToUpdate(lib, release); } } } } else { Tasks.scheduleOnUIThread(this, 250, TimeUnit.MILLISECONDS, this); } }
Example 5
Source File: CancelOrderDialog.java From btdex with GNU General Public License v3.0 | 4 votes |
public CancelOrderDialog(JFrame owner, Market market, AssetOrder order, ContractState state) { super(owner, ModalityType.APPLICATION_MODAL); setDefaultCloseOperation(DISPOSE_ON_CLOSE); setTitle(tr("canc_cancel_order")); isToken = market.getTokenID()!=null; this.market = market; this.order = order; this.state = state; conditions = new JTextPane(); conditions.setContentType("text/html"); conditions.setPreferredSize(new Dimension(80, 160)); conditions.setEditable(false); acceptBox = new JCheckBox(tr("dlg_accept_terms")); // Create a button JPanel buttonPane = new JPanel(new FlowLayout(FlowLayout.RIGHT)); pin = new JPasswordField(12); pin.addActionListener(this); calcelButton = new JButton(tr("dlg_cancel")); okButton = new JButton(tr("dlg_ok")); getRootPane().setDefaultButton(okButton); calcelButton.addActionListener(this); okButton.addActionListener(this); if(Globals.getInstance().usingLedger()) { ledgerStatus = new JTextField(26); ledgerStatus.setEditable(false); buttonPane.add(new Desc(tr("ledger_status"), ledgerStatus)); LedgerService.getInstance().setCallBack(this); } else buttonPane.add(new Desc(tr("dlg_pin"), pin)); buttonPane.add(new Desc(" ", calcelButton)); buttonPane.add(new Desc(" ", okButton)); // set action listener on the button JPanel content = (JPanel)getContentPane(); content.setBorder(new EmptyBorder(4, 4, 4, 4)); JPanel conditionsPanel = new JPanel(new BorderLayout()); conditionsPanel.setBorder(BorderFactory.createTitledBorder(tr("dlg_terms_and_conditions"))); conditionsPanel.add(new JScrollPane(conditions), BorderLayout.CENTER); conditionsPanel.add(acceptBox, BorderLayout.PAGE_END); JPanel centerPanel = new JPanel(new BorderLayout()); centerPanel.add(conditionsPanel, BorderLayout.PAGE_END); content.add(centerPanel, BorderLayout.CENTER); content.add(buttonPane, BorderLayout.PAGE_END); suggestedFee = Globals.getInstance().getNS().suggestFee().blockingGet(); boolean isBuy = false; if(order!=null && order.getType() == AssetOrder.OrderType.BID) isBuy = true; if(state!=null && state.getType() == ContractType.BUY) isBuy = true; StringBuilder terms = new StringBuilder(); terms.append(PlaceOrderDialog.HTML_STYLE); terms.append("<h3>").append(tr("canc_terms_brief", isBuy ? tr("token_buy") : tr("token_sell"), market, isToken ? order.getId() : state.getAddress().getRawAddress())).append("</h3>"); if(isToken) { terms.append("<p>").append(tr("canc_terms_token", NumberFormatting.BURST.format(suggestedFee.getPriorityFee().longValue()))).append("</p>"); } else { terms.append("<p>").append(tr("canc_terms_contract", state.getBalance().toUnformattedString(), NumberFormatting.BURST.format(state.getActivationFee() + suggestedFee.getPriorityFee().longValue())) ).append("</p>"); } conditions.setText(terms.toString()); conditions.setCaretPosition(0); pack(); }
Example 6
Source File: RegisterContractDialog.java From btdex with GNU General Public License v3.0 | 4 votes |
public RegisterContractDialog(Window owner, boolean isBuy) { super(owner, ModalityType.APPLICATION_MODAL); setDefaultCloseOperation(DISPOSE_ON_CLOSE); this.isBuy = isBuy; setTitle(tr("reg_register")); conditions = new JTextPane(); conditions.setPreferredSize(new Dimension(240, 220)); acceptBox = new JCheckBox(tr("dlg_accept_terms")); // The number of contracts to register SpinnerNumberModel numModel = new SpinnerNumberModel(1, 1, 10, 1); numOfContractsSpinner = new JSpinner(numModel); JPanel numOfContractsPanel = new Desc(tr("reg_num_contracts"), numOfContractsSpinner); numOfContractsSpinner.addChangeListener(this); // Create a button JPanel buttonPane = new JPanel(new FlowLayout(FlowLayout.RIGHT)); pin = new JPasswordField(12); pin.addActionListener(this); cancelButton = new JButton(tr("dlg_cancel")); okButton = new JButton(tr("dlg_ok")); cancelButton.addActionListener(this); okButton.addActionListener(this); buttonPane.add(new Desc(tr("dlg_pin"), pin)); buttonPane.add(new Desc(" ", cancelButton)); buttonPane.add(new Desc(" ", okButton)); JPanel content = (JPanel)getContentPane(); content.setBorder(new EmptyBorder(4, 4, 4, 4)); JPanel conditionsPanel = new JPanel(new BorderLayout()); conditionsPanel.setBorder(BorderFactory.createTitledBorder(tr("dlg_terms_and_conditions"))); JScrollPane scroll = new JScrollPane(conditions); scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); scroll.setPreferredSize(conditions.getPreferredSize()); conditionsPanel.add(scroll, BorderLayout.CENTER); conditionsPanel.add(acceptBox, BorderLayout.PAGE_END); JPanel centerPanel = new JPanel(new BorderLayout()); centerPanel.add(conditionsPanel, BorderLayout.CENTER); content.add(numOfContractsPanel, BorderLayout.PAGE_START); content.add(centerPanel, BorderLayout.CENTER); content.add(buttonPane, BorderLayout.PAGE_END); contract = Contracts.getCompiler(isBuy ? ContractType.BUY : ContractType.SELL); stateChanged(null); pack(); }
Example 7
Source File: Opt4JAbout.java From opt4j with MIT License | 4 votes |
@Override public void startup() { Container content = this; content.setLayout(new BorderLayout()); JLabel logoLabel = new JLabel(Icons.getIcon("img/top_logo.png")); logoLabel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); JPanel logo = new JPanel(new BorderLayout()); logo.setBackground(Color.WHITE); logo.add(logoLabel); content.add(logo, BorderLayout.PAGE_START); JTextPane license = new JTextPane(); license.setEditable(false); final JScrollPane licenseScroll = new JScrollPane(license); licenseScroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); StyledDocument doc = license.getStyledDocument(); Style regular = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE); try { doc.insertString(doc.getLength(), LICENSE_TEXT, regular); } catch (BadLocationException e) { e.printStackTrace(); } license.setPreferredSize(new Dimension(360, 100)); content.add(licenseScroll, BorderLayout.CENTER); SwingUtilities.invokeLater(() -> licenseScroll.getVerticalScrollBar().setValue(0)); JPanel footer = new JPanel(new BorderLayout()); footer.setBackground(Color.WHITE); // Add Copyright & Credits String copyright = "<html>Build " + Opt4J.getDateISO() + " <br /> Version " + Opt4J.getVersion() + " \u00a9 Opt4J.org 2007</html>"; JLabel copyrightLabel = new JLabel(copyright); copyrightLabel.setHorizontalAlignment(SwingConstants.CENTER); copyrightLabel.setVerticalAlignment(SwingConstants.BOTTOM); copyrightLabel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); footer.add(copyrightLabel, BorderLayout.EAST); String credits = "<html><p>Credits:<br />"; for (String author : AUTHORS) { credits += author + "<br/>"; } credits += "</p></html>"; JLabel creditsLabel = new JLabel(credits); creditsLabel.setHorizontalAlignment(SwingConstants.CENTER); creditsLabel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); footer.add(creditsLabel, BorderLayout.WEST); content.add(footer, BorderLayout.PAGE_END); }
Example 8
Source File: JCMInfo.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 4 votes |
JHTML(String s) { super(new BorderLayout()); html = new JTextPane(); html.setEditable(false); // need to set this explicitly to fix swing 1.3 bug html.setCaretPosition(0); html.setContentType("text/html"); // Enable posting of form submit events to the hyper link listener final HTMLEditorKit htmlEditor = (HTMLEditorKit)html.getEditorKitForContentType("text/html"); try { // Call htmlEditor.setAutoFormSubmission(false); if available (Java 5+) final Method setAutoFormSubmissionMethod = htmlEditor.getClass() .getMethod("setAutoFormSubmission", new Class[]{ Boolean.TYPE}); setAutoFormSubmissionMethod.invoke(htmlEditor, new Object[]{Boolean.FALSE}); } catch (final Throwable t) { Activator.log.warn("Failed to enable auto form submission for JHTMLBundle.", t); } html.setText(s); html.setCaretPosition(0); html.addHyperlinkListener(new HyperlinkListener() { @Override public void hyperlinkUpdate(HyperlinkEvent ev) { if (ev.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { final URL url = ev.getURL(); try { if (Util.isBundleLink(url)) { final long bid = Util.bidFromURL(url); Activator.disp.getBundleSelectionModel().clearSelection(); Activator.disp.getBundleSelectionModel().setSelected(bid, true); } else if (Util.isImportLink(url)) { JCMInfo.importCfg(JHTML.this); } else { Util.openExternalURL(url); } } catch (final Exception e) { Activator.log.error("Failed to show " + url, e); } } } }); scroll = new JScrollPane(html, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); html.setPreferredSize(new Dimension(300, 300)); add(scroll, BorderLayout.CENTER); }
Example 9
Source File: MainFrame.java From procamcalib with GNU General Public License v2.0 | 4 votes |
private void aboutMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aboutMenuItemActionPerformed String version = MainFrame.class.getPackage().getImplementationVersion(); if (version == null) { version = "unknown"; } JTextPane textPane = new JTextPane(); textPane.setEditable(false); textPane.setContentType("text/html"); textPane.setText( "<font face=sans-serif><strong><font size=+2>ProCamCalib</font></strong> version " + version + "<br>" + "Copyright (C) 2009-2014 Samuel Audet <<a href=\"mailto:[email protected]%28Samuel%20Audet%29\">[email protected]</a>><br>" + "Web site: <a href=\"http://www.ok.ctrl.titech.ac.jp/~saudet/procamcalib/\">http://www.ok.ctrl.titech.ac.jp/~saudet/procamcalib/</a><br>" + "<br>" + "Licensed under the GNU General Public License version 2 (GPLv2).<br>" + "Please refer to LICENSE.txt or <a href=\"http://www.gnu.org/licenses/\">http://www.gnu.org/licenses/</a> for details." ); textPane.setCaretPosition(0); Dimension dim = textPane.getPreferredSize(); dim.height = dim.width*3/4; textPane.setPreferredSize(dim); textPane.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent e) { if(e.getEventType() == EventType.ACTIVATED) { try { Desktop.getDesktop().browse(e.getURL().toURI()); } catch(Exception ex) { Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, "Could not launch browser to \"" + e.getURL()+ "\"", ex); } } } }); // pass the scrollpane to the joptionpane. JDialog dialog = new JOptionPane(textPane, JOptionPane.PLAIN_MESSAGE). createDialog(this, "About"); if ("com.sun.java.swing.plaf.gtk.GTKLookAndFeel".equals(UIManager.getLookAndFeel().getClass().getName())) { // under GTK, frameBackground is white, but rootPane color is OK... // but under Windows, the rootPane's color is funny... Color c = dialog.getRootPane().getBackground(); textPane.setBackground(new Color(c.getRGB())); } else { Color frameBackground = this.getBackground(); textPane.setBackground(frameBackground); } dialog.setVisible(true); }
Example 10
Source File: MainFrame.java From procamtracker with GNU General Public License v2.0 | 4 votes |
private void aboutMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aboutMenuItemActionPerformed String version = MainFrame.class.getPackage().getImplementationVersion(); if (version == null) { version = "unknown"; } JTextPane textPane = new JTextPane(); textPane.setEditable(false); textPane.setContentType("text/html"); textPane.setText( "<font face=sans-serif><strong><font size=+2>ProCamTracker</font></strong> version " + version + "<br>" + "Copyright (C) 2009-2014 Samuel Audet <<a href=\"mailto:[email protected]%28Samuel%20Audet%29\">[email protected]</a>><br>" + "Web site: <a href=\"http://www.ok.ctrl.titech.ac.jp/~saudet/procamtracker/\">http://www.ok.ctrl.titech.ac.jp/~saudet/procamtracker/</a><br>" + "<br>" + "Licensed under the GNU General Public License version 2 (GPLv2).<br>" + "Please refer to LICENSE.txt or <a href=\"http://www.gnu.org/licenses/\">http://www.gnu.org/licenses/</a> for details." ); textPane.setCaretPosition(0); Dimension dim = textPane.getPreferredSize(); dim.height = dim.width*3/4; textPane.setPreferredSize(dim); textPane.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent e) { if(e.getEventType() == EventType.ACTIVATED) { try { Desktop.getDesktop().browse(e.getURL().toURI()); } catch(Exception ex) { Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, "Could not launch browser to \"" + e.getURL()+ "\"", ex); } } } }); // pass the scrollpane to the joptionpane. JDialog dialog = new JOptionPane(textPane, JOptionPane.PLAIN_MESSAGE). createDialog(this, "About"); if ("com.sun.java.swing.plaf.gtk.GTKLookAndFeel".equals(UIManager.getLookAndFeel().getClass().getName())) { // under GTK, frameBackground is white, but rootPane color is OK... // but under Windows, the rootPane's color is funny... Color c = dialog.getRootPane().getBackground(); textPane.setBackground(new Color(c.getRGB())); } else { Color frameBackground = this.getBackground(); textPane.setBackground(frameBackground); } dialog.setVisible(true); }