this.setSize(300, 200); this.setContentPane(getJContentPane()); this.setTitle("JFrame"); if (jContentPane == null) { jContentPane = new JPanel(); jContentPane.setLayout(null); panel.setBounds(61, 11, 81, 140); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); jContentPane.add(panel); panel.add(c1); c1 = new JCheckBox("Check2"); panel.add(c1); c1 = new JCheckBox("Check3"); panel.add(c1); frame.setVisible(true); frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
import java.awt.Color; import javax.swing.JPanel; public class NewClass1 extends javax.swing.JFrame { public NewClass1() { setLayout(null); JPanel panel=new JPanel(); panel.setOpaque(true); add(panel); panel.setBackground(Color.red); panel.setBounds(0,0,400,300); } public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new NewClass1().setVisible(true); } }); } }
JFrame f = new JFrame("AnimationTest"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(this); f.pack(); f.setLocationRelativeTo(null); f.setVisible(true); timer.start(); JTextField field = new JTextField("test"); Dimension d = field.getPreferredSize(); field.setBounds(e.getX(), e.getY(), d.width, d.height); add(field);
import javax.swing.JPanel; import javax.swing.JLabel; public class Snd extends JPanel { /** * Create the panel. */ public Snd() { setLayout(null); Calculate _cal = new Calculate(); JLabel label = new JLabel("New label"); label.setBounds(180, 120, 61, 16); add(label); label.setText(_cal.getNum().get(0).toString()); // problem occurs here } }
setBorder(new LineBorder(Color.BLUE, 3)); setBackground(Color.WHITE); setBounds(0, 0, 100, 100); setOpaque(false); JFrame f = new JFrame("Swing Hello World"); f.add(mc); f.setSize(500, 500); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); f.setVisible(true);
import java.awt.Dimension; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; public class Test { public static void main(String... args) { JFrame frame = new JFrame(); JPanel panel = new JPanel(); for (int i = 0; i < 10; i++) { panel.add(new JButton("Hello-" + i)); } JScrollPane scrollPane = new JScrollPane(panel); scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER); scrollPane.setBounds(50, 30, 300, 50); JPanel contentPane = new JPanel(null); contentPane.setPreferredSize(new Dimension(500, 400)); contentPane.add(scrollPane); frame.setContentPane(contentPane); frame.pack(); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setVisible(true); } }
layeredPane.add(imageContainer, new Integer(50)); layeredPane.add(info, new Integer(100)); this.add(layeredPane); imageContainer.setBounds( 0, 0, image.getIconWidth(), image.getIconHeight() ); info.setBounds( 200, 00, 50, 40 ); JFrame frame = new JFrame(); frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); frame.add( new MyClass( new ImageIcon("logo.png") ) ); frame.pack(); frame.setVisible( true );
import javax.swing.JPanel; import javax.swing.JLabel; import javax.swing.JTextField; import java.awt.Font; public class csView extends JPanel { // Declare those variables here String hhhhh; JLabel Uniqlbl; public csView() { setLayout(null); Uniqlbl = new JLabel("Cashier Name:"); Uniqlbl.setFont(new Font("Tahoma", Font.PLAIN, 16)); Uniqlbl.setBounds(227, 62, 253, 46); add(Uniqlbl); } // Add a setter here public void setHhhhh(String hhhhh) { this.hhhhh = hhhhh; // Edit: Add this line to update the Uniqlbl text Uniqlbl.setText(hhhhh); } }
layeredPane.addMouseListener( this ); layeredPane.addMouseMotionListener( this ); getContentPane().add(layeredPane); chessBoard.setLayout( new GridLayout(8, 8) ); chessBoard.setPreferredSize( boardSize ); chessBoard.setBounds(0, 0, boardSize.width, boardSize.height); layeredPane.add(chessBoard, JLayeredPane.DEFAULT_LAYER); chessBoard.add( square ); frame.setDefaultCloseOperation( DISPOSE_ON_CLOSE ); frame.setResizable( false ); frame.pack(); frame.setLocationRelativeTo( null ); frame.setVisible(true);
import java.awt.*; import java.awt.event.*; import java.applet.*; public class ButtonDemo extends Applet implements ActionListener { public void init() { setLayout(null) Button yes= new Button("Yes"); yes.setBounds(0,30,30,60); add(yes); yes.addActionListener(this); } public void actionPerformed (ActionEvent ae) { } }
private static final int HEIGHT = 800; private Random random = new Random(); private JFrame frame = new JFrame("SimplePaintSurface"); private JPanel tableaux; addRandom(); frame.add(tableaux, BorderLayout.CENTER); JButton add = new JButton("Add"); add.addActionListener(this); frame.add(add, BorderLayout.SOUTH); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(WIDTH, HEIGHT); frame.setLocationRelativeTo(null); frame.setVisible(true); tableaux.requestFocusInWindow(); letter.setBounds(random.nextInt(WIDTH), random.nextInt(HEIGHT), 16, 16); tableaux.add(letter); bounds.width = (int) stringBounds.getWidth(); bounds.height = (int) stringBounds.getHeight(); setBounds(bounds); bounds.width = (int) stringBounds.getWidth(); bounds.height = (int) stringBounds.getHeight(); setBounds(bounds);
import javax.swing.*; public class MyFrame extends JFrame { public MyFrame() { setBounds(100, 100, 491, 310); getContentPane().setLayout(null); JTextArea textField = new JTextArea(); textField.setEditable(false); String str = ""; for (int i = 0; i < 50; ++i) str += "Some text\n"; textField.setText(str); JScrollPane scroll = new JScrollPane(textField); scroll.setBounds(10, 11, 455, 249); // <-- THIS getContentPane().add(scroll); setLocationRelativeTo ( null ); } }
JFrame frame = new JFrame(); frame.setBounds(50, 50, 700, 550); JLabel[] userLabel = new JLabel[6]; userLabel[p] = new JLabel(); userLabel[0].setBounds(10,35,100,50); userLabel[1].setBounds(10,85,100,50); userLabel[2].setBounds(10,135,100,50); userLabel[3].setBounds(10,185,100,50); userLabel[4].setBounds(10,235,100,50); userLabel[0].setText("Width of Frame:"); userLabel[1].setText("Height of Frame:"); frame.add(userLabel[p]); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
import javax.swing.*; public class Example { public static void main(String[] args) { JFrame f = new JFrame(); f.setLayout(null); f.setBounds(50,50, 400,400); JLabel l = new JLabel("你好吗"); l.setBounds(10,100, 50,30); JTextField t = new JTextField("你好吗",20); t.setBounds(100,100,50,30); f.add(l); f.add(t); f.setVisible(true); } }