Java Code Examples for javax.swing.JTextArea.setSize()

The following are Jave code examples for showing how to use setSize() of the javax.swing.JTextArea class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: myster   File: MessageWindow.java   Source Code and License Vote up 8 votes
public MessageTextArea(boolean editable, String text, String labelText) {
    setLayout(new BorderLayout());

    area = new JTextArea("");
    area.setSize(400, 400);
    area.setWrapStyleWord(true);
    area.setAutoscrolls(true);
    area.setLineWrap(true);
    area.setEditable(editable);
    area.setText(text);

    JScrollPane scrollPane = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    scrollPane.getViewport().add(area);
    scrollPane.setDoubleBuffered(true);
    add(scrollPane, "Center");

    JLabel message = new JLabel(labelText);
    add(message, "North");
}
 
Example 2
Project: scorekeeperfrontend   File: DriverCarPanel.java   Source Code and License Vote up 6 votes
protected JTextArea displayArea(int linecount)
{
    JTextArea ta = new JTextArea();
    ta.setEditable(false);
    ta.setLineWrap(false);
    ta.setEnabled(true);

    // ugly hack to set a preferred height based on lines of text
    ta.setSize(100,Short.MAX_VALUE);
    StringBuilder b = new StringBuilder();
    for (int ii = 0; ii < linecount-1; ii++) {
        b.append(ii+"\n"+ii);
    }
    ta.setText(b.toString());
    int h = (int)(ta.getPreferredSize().height*0.9);
    ta.setPreferredSize(new Dimension(Short.MAX_VALUE, h));
    ta.setText("");
    return ta;
}
 
Example 3
Project: JavaGraph   File: MultiLinedEditor.java   Source Code and License Vote up 5 votes
/**
 * Initialises the editor component with the edit string of the user
 * object of <tt>value</tt> (which is required to be a {@link JCell}).
 */
@Override
public Component getGraphCellEditorComponent(org.jgraph.JGraph graph, Object value,
        boolean isSelected) {
    AspectJCell jCell = (AspectJCell) value;
    // fill the set of labels for autocompletion
    this.labels.clear();
    this.labels.addAll(prefixes);
    AspectJModel jmodel = (AspectJModel) graph.getModel();
    TypeGraph type = jmodel.getResourceModel().getGrammar().getTypeGraph();
    for (TypeLabel label : type.getLabels()) {
        this.labels.add(label.text());
    }
    JTextArea result = getEditorComponent();
    // scale with the jGraph
    Font font = Options.getLabelFont().deriveFont(jCell.getVisuals().getFont());
    font = (font != null) ? font : graph.getFont();
    if (graph.getScale() != 1) {
        double scale = graph.getScale();
        Dimension size = result.getSize();
        size.height *= scale;
        size.width *= scale;
        result.setSize(size);
        font = font.deriveFont((float) (font.getSize() * scale));
    }
    result.setFont(font);
    String editString = ((AspectJCell) value).getUserObject().toEditString();
    result.setText(editString);
    result.selectAll();
    return result;
}
 
Example 4
Project: freecol   File: FirstContactDialog.java   Source Code and License Vote up 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);

    MigPanel panel
        = new MigPanel(new MigLayout("wrap 1", "[center]", "[]20"));
    panel.setOpaque(false);

    String headerKey = BASE_KEY + other.getNation().getSuffix();
    String imageKey = IMAGE_BASE_KEY + other.getNationResourceKey();
    if (!Messages.containsKey(headerKey)) {
        headerKey = BASE_KEY + NATIVES_KEY;
        imageKey = IMAGE_BASE_KEY + NATIVES_KEY;
    }
    JLabel header = Utility.localizedHeaderLabel(headerKey,
        SwingConstants.LEADING, FontLibrary.FontSize.MEDIUM);
    JLabel image
        = new JLabel(new ImageIcon(ResourceManager.getImage(imageKey)));
    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().getMiscIconImage(other.getNation()));
    initializeConfirmDialog(frame, false, panel, icon, "yes", "no");
}
 
Example 5
Project: FreeCol   File: FirstContactDialog.java   Source Code and License Vote up 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);

    MigPanel panel
        = new MigPanel(new MigLayout("wrap 1", "[center]", "[]20"));
    panel.setOpaque(false);

    String headerKey = BASE_KEY + other.getNation().getSuffix();
    String imageKey = IMAGE_BASE_KEY + other.getNationResourceKey();
    if (!Messages.containsKey(headerKey)) {
        headerKey = BASE_KEY + NATIVES_KEY;
        imageKey = IMAGE_BASE_KEY + NATIVES_KEY;
    }
    JLabel header = Utility.localizedHeaderLabel(headerKey,
        SwingConstants.LEADING, FontLibrary.FontSize.MEDIUM);
    JLabel image
        = new JLabel(new ImageIcon(ResourceManager.getImage(imageKey)));
    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().getMiscIconImage(other.getNation()));
    initializeConfirmDialog(frame, false, panel, icon, "yes", "no");
}
 
Example 6
Project: freecol   File: Utility.java   Source Code and License Vote up 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;
}
 
Example 7
Project: FreeCol   File: Utility.java   Source Code and License Vote up 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;
}