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

The following are Jave code examples for showing how to use setPreferredSize() 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: incubator-netbeans   File: NotifyDescriptor.java   Source Code and License Vote up 6 votes
/**
* Define a descriptive message to be reported.  In the most common
* usage, the message is just a <code>String</code>.  However, the type
* of this parameter is actually <code>Object</code>.  Its interpretation depends on
* its type:
* <dl compact>
* <dt><code>Object[]</code><dd> A recursively interpreted series of messages.
* <dt>{@link Component}<dd> The <code>Component</code> is displayed in the dialog.
* <dt>{@link javax.swing.Icon}<dd> The <code>Icon</code> is wrapped in a {@link JLabel} and displayed in the dialog.
* <dt>anything else<dd> The {@link Object#toString string representation} of the object.
* </dl>
*
* @param newMessage the <code>Object</code> to report
* @see #getMessage
*/
public void setMessage(Object newMessage) {
    checkMessageValidity(newMessage);
    Object oldMessage = message;

    if (newMessage instanceof String) {
        // bugfix #25457, use JTextArea for word-wrapping
        JTextArea area = new JTextArea((String) newMessage);
        area.setPreferredSize(new Dimension(SIZE_PREFERRED_WIDTH, SIZE_PREFERRED_HEIGHT));
        area.setBackground(UIManager.getColor("Label.background")); // NOI18N
        area.setBorder(BorderFactory.createEmptyBorder());
        area.setLineWrap(true);
        area.setWrapStyleWord(true);
        area.setEditable(false);
        area.setFocusable(true);
        area.getAccessibleContext().setAccessibleName(NbBundle.getMessage(NotifyDescriptor.class, "ACN_NotifyDescriptor_MessageJTextArea")); // NOI18N
        area.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(NotifyDescriptor.class, "ACD_NotifyDescriptor_MessageJTextArea")); // NOI18N
        newMessage = area;
    }

    message = newMessage;
    firePropertyChange(PROP_MESSAGE, oldMessage, newMessage);
}
 
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: incubator-netbeans   File: InstancesView.java   Source Code and License Vote up 5 votes
public SuspendInfoPanel() {
    setLayout(new java.awt.GridBagLayout());
    JTextArea infoText = new JTextArea(NbBundle.getMessage(InstancesView.class, "MSG_NotSuspendedApp"));
    infoText.setEditable(false);
    infoText.setEnabled(false);
    infoText.setBackground(getBackground());
    infoText.setDisabledTextColor(new JLabel().getForeground());
    infoText.setLineWrap(true);
    infoText.setWrapStyleWord(true);
    infoText.setPreferredSize(
            new Dimension(
                infoText.getFontMetrics(infoText.getFont()).stringWidth(infoText.getText()),
                infoText.getPreferredSize().height));
    GridBagConstraints gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 1;
    //gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
    //gridBagConstraints.weightx = 1.0;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.CENTER;
    gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
    add(infoText, gridBagConstraints);
    infoText.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(InstancesView.class, "MSG_NotSuspendedApp"));
    
    JButton pauseButton = new JButton();
    pauseButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            doStopCurrentDebugger();
        }
    });
    org.openide.awt.Mnemonics.setLocalizedText(pauseButton, NbBundle.getMessage(InstancesView.class, "CTL_Pause"));
    pauseButton.setIcon(ImageUtilities.loadImageIcon("org/netbeans/modules/debugger/resources/actions/Pause.gif", false));
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 2;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.CENTER;
    gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
    add(pauseButton, gridBagConstraints);
}
 
Example 4
Project: zooracle   File: IndividualDataPanel.java   Source Code and License Vote up 4 votes
public IndividualDataPanel(ZooracleContentPanel zooracleContentPanel)
	{
		this.zooracleContentPanel = zooracleContentPanel;
		
		labelName     = GUISettings.getDefaultLabel(Locale.labelName, lw, lh, a, va); 
		labelGender   = GUISettings.getDefaultLabel(Locale.labelSex, lw, lh, a, va);
		labelComment  = GUISettings.getDefaultLabel(Locale.labelComment, lw, 80, a, va);
		labelMetaData = GUISettings.getDefaultLabel(Locale.labelMetaData, lw, 100, a, va);
		
		textFieldName = new JTextField("");   textFieldName.setPreferredSize(new Dimension(200, 30)); textFieldName.setBorder(BorderFactory.createLineBorder(Color.BLACK));
		textAreaComment = new JTextArea();  textAreaComment.setPreferredSize(new Dimension(200, 80)); 
		textAreaComment.setBorder(BorderFactory.createLineBorder(Color.BLACK));
		
		comboBoxGender = new JComboBox(); 
//		comboBoxGender.setBorder(BorderFactory.createLineBorder(Color.BLACK));
		for (Object item : Locale.dropDownGenders)
			comboBoxGender.addItem(item);
		
		// Create some items to add to the list
		String listData[] =
		{
			"BT_1.1",
			"BT_1.2",
			"BT_1.3",
			"BT_1.4"
		};
		
		metaList = new JList(listData);
		JScrollPane metaScrollPane = new JScrollPane(metaList, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
		metaScrollPane.setPreferredSize(new Dimension(200, 100));
		
		
		this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		
		JPanel panelName     = new JPanel(new FlowLayout(FlowLayout.LEFT)); 
		JPanel panelGender   = new JPanel(new FlowLayout(FlowLayout.LEFT));
		JPanel panelComment  = new JPanel(new FlowLayout(FlowLayout.LEFT));
		JPanel panelMetaList = new JPanel(new FlowLayout(FlowLayout.LEFT));
		
		
		panelName.add(labelName);
		panelName.add(textFieldName);

		panelGender.add(labelGender);
		panelGender.add(comboBoxGender);

		panelComment.add(labelComment);
		panelComment.add(textAreaComment);

		panelMetaList.add(labelMetaData);
		panelMetaList.add(metaScrollPane);
		
		this.add(panelName);
		this.add(panelGender);
		this.add(panelComment);
		this.add(panelMetaList);
		
		this.setBackground(GUISettings.windowColor);
		this.setForeground(GUISettings.windowColor);
		
		this.setMinimumSize(new Dimension(300, 500));
		
		
	}
 
Example 5
Project: freecol   File: Utility.java   Source Code and License Vote up 2 votes
/**
 * Gets a text area with standard settings suitable for use in FreeCol
 * panels, which can not adapt their size.
 *
 * @param text The text to display in the text area.
 * @param size The size of the area to display the text in.
 * @return A suitable text area.
 */
public static JTextArea getDefaultTextArea(String text, Dimension size) {
    JTextArea textArea = createTextArea(text);
    textArea.setPreferredSize(size);
    return textArea;
}
 
Example 6
Project: FreeCol   File: Utility.java   Source Code and License Vote up 2 votes
/**
 * Gets a text area with standard settings suitable for use in FreeCol
 * panels, which can not adapt their size.
 *
 * @param text The text to display in the text area.
 * @param size The size of the area to display the text in.
 * @return A suitable text area.
 */
public static JTextArea getDefaultTextArea(String text, Dimension size) {
    JTextArea textArea = createTextArea(text);
    textArea.setPreferredSize(size);
    return textArea;
}