JPanel: setPreferredSize(Dimension preferredSize) : JPanel « javax.swing « Java by API






JPanel: setPreferredSize(Dimension preferredSize)

  

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;

import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.border.Border;

public class Main {
  public static void main(String args[]) {
    JFrame f = new JFrame("Label Demo");
    f.setLayout(new FlowLayout());
    f.setSize(200, 360);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
    JLabel label= new JLabel("asdf");
    Border border = BorderFactory.createLineBorder(Color.BLACK);
    label.setBorder(border);
    label.setPreferredSize(new Dimension(150, 100));
    f.add(label);

    f.setVisible(true);
  }
}

   
    
  








Related examples in the same category

1.JPanel: addAncestorListener(AncestorListener lis)
2.JPanel: addContainerListener(ContainerListener l)
3.JPanel: addMouseListener(MouseListener mous)
4.JPanel: addMouseMotionListener(MouseMotionListener lis)
5.JPanel: addKeyListener(KeyListener l)
6.JPanel: getFocusTraversalKeys(int id)
7.JPanel: isFocusCycleRoot()
8.JPanel: paintComponent(Graphics g)
9.JPanel: repaint()
10.JPanel: setBackground(Color c)
11.JPanel: setBorder(Border border)
12.JPanel: setComponentPopupMenu(JPopupMenu popup)
13.JPanel: setFocusCycleRoot(boolean value)
14.JPanel: setFocusTraversalPolicyProvider(boolean value)
15.JPanel: setLayout(null)
16.JPanel: setOpaque(boolean isOpaque)
17.JPanel: setToolTipText(String htmlString)
18.extends JPanel