List of usage examples for javax.swing JFrame add
public Component add(Component comp)
From source file:MyLabel.java
public static void main(String[] args) { String lyrics = "<html>Line<br>line<br>line</html>"; JPanel panel = new JPanel(); panel.setLayout(new BorderLayout(10, 10)); JLabel label = new JLabel(lyrics); label.setFont(new Font("Georgia", Font.PLAIN, 14)); label.setForeground(new Color(50, 50, 25)); panel.add(label, BorderLayout.CENTER); panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); JFrame f = new JFrame(); f.add(panel); f.pack();// w ww. j av a 2 s .com f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame(); f.add(new JPanel() { @Override//from ww w . j a v a 2s .co m public Dimension getPreferredSize() { return new Dimension(320, 240); } }); f.pack(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice defaultScreen = ge.getDefaultScreenDevice(); Rectangle rect = defaultScreen.getDefaultConfiguration().getBounds(); int x = (int) rect.getMaxX() - f.getWidth(); int y = (int) rect.getMaxY() - f.getHeight(); f.setLocation(x, y); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { String[] items = { "Sun", "Mon", "Tues", "Wed", "Thurs", "Fri", "Sat" }; JList<String> myJList = new JList(items) { @Override//from ww w .ja va 2s .c o m protected void processMouseEvent(MouseEvent e) { int modifiers = e.getModifiers() | InputEvent.CTRL_MASK; int modifiersEx = e.getModifiersEx() | InputEvent.CTRL_MASK; MouseEvent myME = new MouseEvent((Component) e.getSource(), e.getID(), e.getWhen(), modifiers, e.getX(), e.getY(), e.getXOnScreen(), e.getYOnScreen(), e.getClickCount(), e.isPopupTrigger(), e.getButton()); super.processMouseEvent(myME); } }; JFrame f = new JFrame(); f.add(new JScrollPane(myJList)); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.pack(); f.setLocationRelativeTo(null); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { GraphicsDevice[] sds = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices(); for (GraphicsDevice sd : sds) { System.out.println(sd.getIDstring()); GraphicsConfiguration gc = sd.getDefaultConfiguration(); JFrame f = new JFrame(gc); f.add(new JLabel(sd.getIDstring())); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.pack();/* ww w . j av a2s .c o m*/ centerOn(f, gc); f.setVisible(true); } }
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame(); f.add(new JPanel() { @Override//w w w .j av a2 s . c o m public Dimension getPreferredSize() { return new Dimension(320, 240); } }); f.pack(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice defaultScreen = ge.getDefaultScreenDevice(); Rectangle rect = defaultScreen.getDefaultConfiguration().getBounds(); int x = (int) rect.getMaxX() - f.getWidth(); int y = 0; f.setLocation(x, y); f.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JTree tree = new JTree(); TreeSelectionListener treeSelectionListener = new TreeSelectionListener() { @Override/* www . jav a 2s. com*/ public void valueChanged(TreeSelectionEvent treeSelectionEvent) { JTree treeSource = (JTree) treeSelectionEvent.getSource(); System.out.println("Min: " + treeSource.getMinSelectionRow()); System.out.println("Max: " + treeSource.getMaxSelectionRow()); System.out.println("Lead: " + treeSource.getLeadSelectionRow()); System.out.println("Row: " + treeSource.getSelectionRows()[0]); } }; tree.addTreeSelectionListener(treeSelectionListener); JFrame frame = new JFrame(); frame.add(new JScrollPane(tree)); frame.setSize(300, 150); frame.setVisible(true); }
From source file:PrintLineByLine.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.add(new PrintLineByLine()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(420, 250);/*from w w w. ja v a2 s . c o m*/ frame.setVisible(true); }
From source file:TextBox3D.java
public static void main(String[] args) { JFrame f = new JFrame(); f.add(new TextBox3D("Help Me", 200, 200)); f.setSize(300, 300);//from ww w . ja v a 2 s . c o m f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JTextField smallField = new JTextField(5); JTextField largeField = new JTextField(20); JPanel gui = new JPanel(new FlowLayout()); gui.add(smallField);// www . ja va 2 s . com gui.add(largeField); JFrame f = new JFrame("Text Field Size"); f.add(gui); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); f.pack(); f.setLocationByPlatform(true); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame(); f.add(new Main()); f.setSize(300, 300);//from w w w . j a va 2 s. c o m f.setVisible(true); }