Java Code Examples for javax.swing.JTextArea#getPreferredSize()
The following examples show how to use
javax.swing.JTextArea#getPreferredSize() .
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: MultiLineToolTipUI.java From osp with GNU General Public License v3.0 | 6 votes |
@Override public Dimension getPreferredSize(JComponent c) { String tipText = ((JToolTip)c).getTipText(); if (tipText==null) return new Dimension(0,0); textArea = new JTextArea(tipText); textArea.setBorder(BorderFactory.createEmptyBorder(0, 2, 2, 2)); rendererPane.removeAll(); rendererPane.add(textArea); textArea.setWrapStyleWord(true); textArea.setLineWrap(false); Dimension dim = textArea.getPreferredSize(); dim.height += 2; dim.width += 2; return dim; }
Example 2
Source File: MotionDemo.java From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License | 5 votes |
private JComponent buildContentPane() { JPanel panel = new JPanel(null); int x = 16; int y = 16; Dimension size; textArea = new JTextArea("Type your document here.", 12, 25); textArea.setBorder(BorderFactory.createLineBorder(Color.BLACK)); size = textArea.getPreferredSize(); textArea.setBounds(x, y, size.width, size.height); panel.add(textArea); x += size.width + 6; saveButton = new JButton("Save..."); size = saveButton.getPreferredSize(); saveButton.setBounds(x, y, size.width, size.height); panel.add(saveButton); y += size.height + 4; openButton = new JButton("Open..."); size = openButton.getPreferredSize(); openButton.setBounds(x, y, size.width, size.height); panel.add(openButton); x += size.width + 16; y = textArea.getPreferredSize().height + 16 + 16; panel.setPreferredSize(new Dimension(x, y)); return panel; }
Example 3
Source File: MainFrame.java From procamcalib with GNU General Public License v2.0 | 5 votes |
private void readmeMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_readmeMenuItemActionPerformed try { JTextArea textArea = new JTextArea(); Font font = textArea.getFont(); textArea.setFont(new Font("Monospaced", font.getStyle(), font.getSize())); textArea.setEditable(false); String text = ""; BufferedReader r = new BufferedReader(new FileReader( myDirectory + File.separator + "../README.md")); String line; while ((line = r.readLine()) != null) { text += line + '\n'; } textArea.setText(text); textArea.setCaretPosition(0); textArea.setLineWrap(true); textArea.setWrapStyleWord(true); textArea.setColumns(80); // stuff it in a scrollpane with a controlled size. JScrollPane scrollPane = new JScrollPane(textArea); Dimension dim = textArea.getPreferredSize(); dim.height = dim.width*50/80; scrollPane.setPreferredSize(dim); // pass the scrollpane to the joptionpane. JDialog dialog = new JOptionPane(scrollPane, JOptionPane.PLAIN_MESSAGE). createDialog(this, "README"); dialog.setResizable(true); dialog.setModalityType(ModalityType.MODELESS); dialog.setVisible(true); } catch (Exception ex) { Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex); } }
Example 4
Source File: MainFrame.java From procamtracker with GNU General Public License v2.0 | 5 votes |
private void readmeMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_readmeMenuItemActionPerformed try { JTextArea textArea = new JTextArea(); Font font = textArea.getFont(); textArea.setFont(new Font("Monospaced", font.getStyle(), font.getSize())); textArea.setEditable(false); String text = ""; BufferedReader r = new BufferedReader(new FileReader( myDirectory + File.separator + "../README.md")); String line; while ((line = r.readLine()) != null) { text += line + '\n'; } textArea.setText(text); textArea.setCaretPosition(0); textArea.setLineWrap(true); textArea.setWrapStyleWord(true); textArea.setColumns(80); // stuff it in a scrollpane with a controlled size. JScrollPane scrollPane = new JScrollPane(textArea); Dimension dim = textArea.getPreferredSize(); dim.height = dim.width*50/80; scrollPane.setPreferredSize(dim); // pass the scrollpane to the joptionpane. JDialog dialog = new JOptionPane(scrollPane, JOptionPane.PLAIN_MESSAGE). createDialog(this, "README"); dialog.setResizable(true); dialog.setModalityType(ModalityType.MODELESS); dialog.setVisible(true); } catch (Exception ex) { Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex); } }
Example 5
Source File: FatherDetailPanel.java From freecol with GNU General Public License v2.0 | 4 votes |
/** * Builds the details panel for the given FoundingFather. * * @param father The {@code FoundingFather} to build a panel for. * @param panel The detail panel to build. */ public void buildDetail(FoundingFather father, JPanel panel) { panel.setLayout(new MigLayout("wrap 2, fillx, gapx 20", "", "")); String name = Messages.getName(father); String type = Messages.message(father.getTypeKey()); String text = name + " (" + type + ")"; JLabel header = new JLabel(text); header.setFont(FontLibrary.createCompatibleFont(text, FontLibrary.FontType.HEADER, FontLibrary.FontSize.SMALL)); Image image = ImageLibrary.getFoundingFatherImage(father, false); JLabel label = new JLabel(new ImageIcon(image)); StringTemplate template = StringTemplate.label("") .add(Messages.descriptionKey(father)) .addName("\n\n[") .add(father.getId() + ".birthAndDeath") .addName("] ") .add(father.getId() + ".text"); final Turn turn = getMyPlayer().getElectionTurns().get(name); if (turn != null) { template .addName("\n\n") .add("report.continentalCongress.elected") .addName(" ") .addStringTemplate(turn.getLabel()); } panel.add(header, "span, align center, wrap 40"); panel.add(label, "top"); JTextArea description = Utility.localizedTextArea(template, 20); panel.add(description, "top, growx"); Dimension hSize = header.getPreferredSize(), lSize = label.getPreferredSize(), dSize = description.getPreferredSize(), size = new Dimension(); size.setSize(lSize.getWidth() + dSize.getWidth() + 20, hSize.getHeight() + lSize.getHeight() + 10); panel.setPreferredSize(size); }