javax.swing.JTextArea.setSize()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(8.2k)|赞(0)|评价(0)|浏览(227)

本文整理了Java中javax.swing.JTextArea.setSize()方法的一些代码示例,展示了JTextArea.setSize()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JTextArea.setSize()方法的具体详情如下:
包路径:javax.swing.JTextArea
类名称:JTextArea
方法名:setSize

JTextArea.setSize介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

ta.setSize(width, Short.MAX_VALUE);
return p;

代码示例来源:origin: org.netbeans.api/org-openide-dialogs

@Override
public Component getListCellRendererComponent(
  JList list, Object value, int index, boolean isSelected, boolean cellHasFocus
) {
  if (index == selected) {
    numberLabel.setFont(doDeriveFont(numberLabel.getFont(), Font.BOLD));
    ta.setFont(doDeriveFont(ta.getFont(), Font.BOLD));
  } else {
    numberLabel.setFont(doDeriveFont(numberLabel.getFont(), Font.PLAIN));
    ta.setFont(doDeriveFont(ta.getFont(), Font.PLAIN));
  }
  if (contentNumbered) {
    numberLabel.setText(Integer.toString(index + 1) + "."); // NOI18N
  }
  // #21322: on JDK1.4 wrapping width is cleared between two rendering runs
  Insets taInsets = ta.getInsets();
  ta.setSize(taWidth, taInsets.top + taInsets.bottom + 1);
  ta.setText((String) value);
  return this;
}

代码示例来源:origin: org.netbeans.api/org-openide-dialogs

ta.setSize(taWidth, taInsets.top + taInsets.bottom + 1);

代码示例来源:origin: stackoverflow.com

public class MyTextArea extends JScrollPanel{   

  public JTextArea ta = new JTextArea();

  public MyTextArea(){
    ta.setEditable(true);
    ta.setSize(500, 500);
    setViewPortView(ta);
  }
}

代码示例来源:origin: stackoverflow.com

JTextArea textArea = new JTextArea();
textArea.setText(getText());
textArea.setSize(limit, Short.MAX_VALUE); // limit = width in pixels, e.g. 500
textArea.setWrapStyleWord(true);
textArea.setLineWrap(true);

代码示例来源:origin: stackoverflow.com

JTextArea textArea = new JTextArea(longString);
textArea.setSize( new Dimension(200, 16) );

代码示例来源:origin: sarahtattersall/PIPE

/**
 * Set the text for the annotation
 * @param text of the annotation 
 */
public void setText(String text) {
  noteText.setText(text);
  noteText.setSize(noteText.getPreferredSize());
}

代码示例来源:origin: stackoverflow.com

JTextArea textArea = new JTextArea();
textArea.setLineWrap( true );
textArea.setWrapStyleWord( true );
textArea.setText("one two three four five six seven eight nine ten");
System.out.println("000: " + textArea.getPreferredSize());
textArea.setSize(100, 1);
System.out.println("100: " + textArea.getPreferredSize());
textArea.setSize( textArea.getPreferredSize() );

代码示例来源:origin: tflobbe/solrmeter

private Component createStackTrace(OperationException exception) {
  JTextArea textArea = new JTextArea();
  textArea.setEditable(false);
  textArea.setOpaque(false);
  textArea.setBorder(null);
  textArea.setText(SwingUtils.getStackTraceString(exception));
  textArea.setSize(200, 200);
  exception.printStackTrace();
  return new JScrollPane(textArea);
}

代码示例来源:origin: mikaelhg/openblocks

public Dimension getPreferredSize(JComponent c) {
    String tipText = ((JToolTip) c).getTipText();
    if (tipText == null) {
      return new Dimension(0, 0);
    }
    textArea.setText(tipText);
    Dimension d = textArea.getPreferredSize();
    d.width = Math.min(d.width, WIDTH);
    d.height++;
    textArea.setSize(d);
    return d;
    //return textArea.getPreferredSize();
  }
}

代码示例来源:origin: edu.illinois.cs.cogcomp/DatalessClassification

public void result_panel(HashMap<Integer, List<LabelKeyValuePair>> labelResultsInDepth){
  m= new JFrame("Customized Tree");
  m.setSize(500, 300);
  panel3 = new JPanel();
  JTextArea text3 = new JTextArea();
  text3.setSize(400,200);
  text3.setLocation(30, 30);
  text3.setLineWrap(true);
  text3.setMaximumSize( text3.getPreferredSize() );
  int size=labelResultsInDepth.size()-1;
  for(int j=0;j<labelResultsInDepth.get(size).size();j++){
    text3.append("The label name is "+labelResultsInDepth.get(size).get(j).labelName+"\n");
    
  }
  panel3.add(text3);
  m.setContentPane(panel3);
  m.setVisible(true);
}

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/openide

public Component getListCellRendererComponent(
  JList list,
  Object value,
  int index,
  boolean isSelected,
  boolean cellHasFocus)
{
  if (index == selected) {
    numberLabel.setFont(numberLabel.getFont().deriveFont(Font.BOLD));
    ta.setFont(ta.getFont().deriveFont(Font.BOLD));
  } else {
    numberLabel.setFont(numberLabel.getFont().deriveFont(Font.PLAIN));
    ta.setFont(ta.getFont().deriveFont(Font.PLAIN));
  }
  
  if (contentNumbered) {
    numberLabel.setText(Integer.toString(index + 1) + "."); // NOI18N
  }
    // #21322: on JDK1.4 wrapping width is cleared between two rendering runs
  Insets taInsets = ta.getInsets();
  ta.setSize(taWidth, 
        taInsets.top + taInsets.bottom + 1);
  ta.setText((String)value);
  return this;
}

代码示例来源:origin: stackoverflow.com

public JTextArea createTextAreaFitToText(String message, Dimension minimalSize){

    JTextArea aMessagePanel = new JTextArea();
    aMessagePanel.setText(message);

    /*for modelToView to work, the text area has to be sized. It doesn't matter if it's visible or not.*/
    aMessagePanel.setPreferredSize(minimalSize);
    aMessagePanel.setSize(minimalSize);            

    Rectangle r = aMessagePanel.modelToView(aMessagePanel.getDocument().getLength()); 

    Dimension d = new Dimension(minimalSize.width, r.y + r.height);
    aMessagePanel.setPreferredSize(d);
    return aMessagePanel;

}

代码示例来源:origin: sarahtattersall/PIPE

/**
 * Adjust the right horizontal of the annotation
 * @param dx x offset
 */
public void adjustRight(int dx) {
  if (GUIConstants.ANNOTATION_MIN_WIDTH <= noteText.getWidth() + dx) {
    noteText.setSize(new Dimension(noteText.getWidth() + dx, noteText.getHeight()));
  }
}

代码示例来源:origin: sarahtattersall/PIPE

/**
 * Adjust the bottom vertical of the annotation
 * @param dy y offset
 */
public void adjustBottom(int dy) {
  if (noteText.getPreferredSize().height <= noteText.getHeight() + dy) {
    noteText.setSize(new Dimension(noteText.getWidth(), noteText.getHeight() + dy));
  }
}

代码示例来源:origin: sarahtattersall/PIPE

/**
 * Adjust the left horizontal of the annotation
 * @param dx x offset
 */
public void adjustLeft(int dx) {
  if (GUIConstants.ANNOTATION_MIN_WIDTH <= noteText.getWidth() - dx) {
    noteText.setSize(new Dimension(noteText.getWidth() - dx, noteText.getHeight()));
    setLocation(getX() + dx, getY());
    originalX += dx;
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-lib-profiler-ui

private static Color getGTKProfilerResultsBackground() {
  int[] pixels = new int[1];
  pixels[0] = -1;
  
  // Prepare textarea to grab the color from
  JTextArea textArea = new JTextArea();
  textArea.setSize(new Dimension(10, 10));
  textArea.doLayout();
  
  // Print the textarea to an image
  Image image = new BufferedImage(textArea.getSize().width, textArea.getSize().height, BufferedImage.TYPE_INT_RGB);
  textArea.printAll(image.getGraphics());
  
  // Grab appropriate pixels to get the color
  PixelGrabber pixelGrabber = new PixelGrabber(image, 5, 5, 1, 1, pixels, 0, 1);
  try {
    pixelGrabber.grabPixels();
    if (pixels[0] == -1) return Color.WHITE; // System background not customized
  } catch (InterruptedException e) {
    return getNonGTKProfilerResultsBackground();
  }
  
  return pixels[0] != -1 ? new Color(pixels[0]) : getNonGTKProfilerResultsBackground();
}

代码示例来源:origin: sarahtattersall/PIPE

/**
 * Adjust the top vertical of the annotation
 * @param dy y offset
 */
public void adjustTop(int dy) {
  if (noteText.getPreferredSize().height <= noteText.getHeight() - dy) {
    noteText.setSize(new Dimension(noteText.getWidth(), noteText.getHeight() - dy));
    setLocation(getX(), getY() + dy);
    originalY += dy;
  }
}

代码示例来源:origin: sarahtattersall/PIPE

/**
 * Constructor
 * @param model underlying model
 * @param controller Petri net controller for the Petri net the annotation is house in
 * @param parent parent of this view
 */
Note(Annotation model, PetriNetController controller, Container parent) {
  super(model.getId(), model, controller, parent);
  initialize(model.getX(), model.getY());
  noteText.setText(model.getText());
  noteText.setSize(model.getWidth(), model.getHeight());
}

代码示例来源:origin: sarahtattersall/PIPE

/**
 * Calculates the BoundsOffsets used for setBounds() method
 *
 * Implemented because the canvas has no layout manager
 *
 */
public void updateBounds() {
  int newHeight = noteText.getPreferredSize().height;
  if (noteText.getHeight() < newHeight && newHeight >= noteText.getMinimumSize().height) {
    noteText.setSize(noteText.getWidth(), newHeight);
  }
  int rectWidth = noteText.getWidth() + GUIConstants.RESERVED_BORDER;
  int rectHeight = noteText.getHeight() + GUIConstants.RESERVED_BORDER;
  noteRect.setFrame(GUIConstants.RESERVED_BORDER / 2, GUIConstants.RESERVED_BORDER / 2, rectWidth, rectHeight);
  setSize(rectWidth + GUIConstants.ANNOTATION_SIZE_OFFSET, rectHeight + GUIConstants.ANNOTATION_SIZE_OFFSET);
  noteText.setLocation((int) noteRect.getX() + (rectWidth - noteText.getWidth()) / 2,
      (int) noteRect.getY() + (rectHeight - noteText.getHeight()) / 2);
  bounds.setBounds(model.getX() - 20, model.getY() - 20,
      rectWidth + GUIConstants.RESERVED_BORDER + GUIConstants.ANNOTATION_SIZE_OFFSET + 20,
      rectHeight + GUIConstants.RESERVED_BORDER + GUIConstants.ANNOTATION_SIZE_OFFSET + 20);
  setBounds(bounds);
}

相关文章

JTextArea类方法