Java Code Examples for javax.swing.JTextArea#setSize()
The following examples show how to use
javax.swing.JTextArea#setSize() .
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: TableCellLongTextRenderer.java From WhiteRabbit with Apache License 2.0 | 5 votes |
@Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { final JTextArea jtext = new JTextArea(); jtext.setText((String)value); jtext.setWrapStyleWord(true); jtext.setLineWrap(true); jtext.setFont(table.getFont()); jtext.setSize(table.getColumn(table.getColumnName(column)).getWidth(), (int)jtext.getPreferredSize().getHeight()); jtext.setMargin(new Insets(10,5,10,5)); return jtext; }
Example 2
Source File: HeaderPanel.java From saros with GNU General Public License v2.0 | 5 votes |
/** * Method creates header panel with given title and description * * @param title header title * @param text header description */ private void create(String title, String text) { setLayout(new FlowLayout()); Icon icon = IconManager.SESSION_INVITATION_ICON; textMain = new JTextArea(); textMain.setEditable(false); textTitle = new JLabel(); String textConvertedToJLabelHTML = convertTextToJLabelHTML(title); JPanel titlePanel = new JPanel(); titlePanel.setLayout(new FlowLayout(FlowLayout.LEFT)); titlePanel.setBackground(backColor); textTitle.setText(textConvertedToJLabelHTML); titlePanel.add(textTitle); textMain.setText(text); textMain.setSize(500, 100); textMain.setWrapStyleWord(true); textMain.setLineWrap(true); JPanel textPanel = new JPanel(); textPanel.setLayout(new BoxLayout(textPanel, BoxLayout.Y_AXIS)); textPanel.add(titlePanel); textPanel.add(textMain); textPanel.setBackground(backColor); add(textPanel); JLabel lblIcon = new JLabel(); lblIcon.setIcon(icon); add(lblIcon); setBackground(backColor); }
Example 3
Source File: JTableLogs.java From mts with GNU General Public License v3.0 | 4 votes |
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { JTextArea jTextArea = super.getJTextArea(isSelected); TextEvent textEvent = (TextEvent) table.getModel().getValueAt(row, column); if (null == value) { jTextArea.setText(""); jTextArea.setBackground(Color.WHITE); jTextArea.setForeground(Color.BLACK); } else { String text = textEvent.getText(); jTextArea.setText(text); jTextArea.setBackground(GuiHelper.getColorForTopic(textEvent.getTopic())); jTextArea.setForeground(GuiHelper.getColorForLevel(textEvent.getLevel())); jTextArea.setMinimumSize(new Dimension(table.getRowHeight(), table.getRowHeight())); // to get the prefered height jTextArea.setSize(table.getColumnModel().getColumn(column).getWidth(), -1); jTextArea.setSize(table.getColumnModel().getColumn(column).getWidth(), (int) jTextArea.getPreferredSize().getHeight()); int preferedHeight = (int) Math.round(jTextArea.getPreferredSize().getHeight()); // set the prefered height if is different if (table.getRowHeight(row) != preferedHeight && table.getRowHeight(row) != table.getRowHeight()) { table.setRowHeight(row, preferedHeight); } if (search != null) { if (text.toLowerCase().contains(search)) { jTextArea.setBackground(Color.ORANGE); jTextArea.setForeground(Color.BLACK); } } if ((row == index) && (index > -1)) { jTextArea.setBackground(Color.YELLOW); jTextArea.setForeground(Color.BLACK); // table.setRowHeight(row, (int) jTextArea.getPreferredSize().getHeight()); } } if (table.getRowHeight(row) != table.getRowHeight()) { jTextArea.setToolTipText("Click to collapse"); } return jTextArea; }
Example 4
Source File: FirstContactDialog.java From freecol with GNU General Public License v2.0 | 4 votes |
/** * Create an FirstContactDialog. * * @param freeColClient The {@code FreeColClient} for the game. * @param frame The owner frame. * @param player The {@code Player} making contact. * @param other The {@code Player} to contact. * @param tile An optional {@code Tile} on offer. * @param settlementCount The number of settlements the other * player has. */ public FirstContactDialog(FreeColClient freeColClient, JFrame frame, Player player, Player other, Tile tile, int settlementCount) { super(freeColClient, frame); JPanel panel = new MigPanel(new MigLayout("wrap 1", "[center]", "[]20")); panel.setOpaque(false); String headerKey = BASE_KEY + other.getNation().getSuffix(); if (!Messages.containsKey(headerKey)) headerKey = BASE_KEY + NATIVES; JLabel header = Utility.localizedHeaderLabel(headerKey, SwingConstants.LEADING, FontLibrary.FontSize.MEDIUM); JLabel image = new JLabel(new ImageIcon(ImageLibrary .getMeetingImage(other))); image.setOpaque(false); JTextArea tutorial = null; if (!player.hasContactedIndians() && freeColClient.tutorialMode()) { tutorial = Utility.localizedTextArea(TUTORIAL_KEY); } String messageId = (tile != null) ? "firstContactDialog.welcomeOffer.text" : "firstContactDialog.welcomeSimple.text"; String type = ((IndianNationType)other.getNationType()) .getSettlementTypeKey(true); JTextArea text = Utility.localizedTextArea(StringTemplate .template(messageId) .addStringTemplate("%nation%", other.getNationLabel()) .addName("%camps%", Integer.toString(settlementCount)) .add("%settlementType%", type)); // Resize the text areas to better match the image. int columns = (int)Math.floor(text.getColumns() * image.getPreferredSize().getWidth() / text.getPreferredSize().getWidth()); text.setColumns(columns); text.setSize(text.getPreferredSize()); if (tutorial != null) { tutorial.setColumns(columns); tutorial.setSize(tutorial.getPreferredSize()); } panel.add(header); panel.add(image); if (tutorial != null) panel.add(tutorial); panel.add(text); panel.setSize(panel.getPreferredSize()); ImageIcon icon = new ImageIcon(getImageLibrary() .getScaledNationImage(other.getNation())); initializeConfirmDialog(frame, false, panel, icon, "yes", "no"); }
Example 5
Source File: Utility.java From freecol with GNU General Public License v2.0 | 3 votes |
/** * Gets a text area with standard settings suitable for use in FreeCol * panels, which adapt their size based on what they contain. * * @param text The text to display in the text area. * @param columns The em-width number of columns to display the text in. * @return A suitable text area. */ public static JTextArea getDefaultTextArea(String text, int columns) { JTextArea textArea = createTextArea(text); textArea.setColumns(columns); textArea.setSize(textArea.getPreferredSize()); return textArea; }