List of usage examples for javax.swing JFrame setLocationRelativeTo
public void setLocationRelativeTo(Component c)
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame("Test"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTable table = new JTable(new String[][] { { "One" }, { "Two" }, { "Three" } }, new String[] { "Ordinal" }); table.addRowSelectionInterval(1, 1); f.add(new JScrollPane(table)); f.pack();//from www . ja v a 2s . c o m f.setLocationRelativeTo(null); f.setVisible(true); }
From source file:aurelienribon.gdxsetupui.ui.Main.java
public static void main(String[] args) { parseArgs(args);//from www . j av a 2 s . com SwingUtilities.invokeLater(new Runnable() { @Override public void run() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException ex) { } catch (InstantiationException ex) { } catch (IllegalAccessException ex) { } catch (UnsupportedLookAndFeelException ex) { } SwingStyle.init(); ArStyle.init(); JFrame frame = new JFrame("LibGDX Project Setup (gdx-setup-ui)"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setContentPane(new MainPanel()); frame.setSize(1100, 600); frame.setLocationRelativeTo(null); frame.setVisible(true); } }); }
From source file:MouseMoveScale.java
public static void main(String[] args) { JFrame frame = new JFrame("Moving and Scaling"); MouseMoveScale m = new MouseMoveScale(); m.setDoubleBuffered(true);/* ww w .j a va 2s. c om*/ frame.add(m); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(300, 300); frame.setLocationRelativeTo(null); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { Object[][] rowData = { { "Hello", "World" } }; Object[] columnNames = { "A", "B" }; JTable table;//from w w w .j av a2 s. c o m DefaultTableModel model; model = new DefaultTableModel(rowData, columnNames); table = new JTable(); table.setModel(model); JButton add = new JButton("Add"); add.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { model.addRow(rowData[0]); } }); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container c = f.getContentPane(); c.setLayout(new BorderLayout()); c.add(add, BorderLayout.SOUTH); c.add(new JScrollPane(table), BorderLayout.CENTER); f.pack(); f.setLocationRelativeTo(null); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame(); frame.setResizable(false);/*from w w w.j a v a2s . c om*/ removeButtons(frame); JPanel panel = new JPanel(new GridBagLayout()); JButton button = new JButton("Exit"); panel.add(button, new GridBagConstraints()); frame.getContentPane().add(panel); frame.setSize(400, 300); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); button.addActionListener(e -> System.exit(0)); }
From source file:SimpleDnD.java
public static void main(String[] args) { JTextField field = new JTextField(10); JButton button = new JButton("Button"); JFrame f = new JFrame(); f.setTitle("Simple Drag & Drop"); f.setLayout(new FlowLayout()); f.add(button);// w w w . jav a 2 s. c o m f.add(field); field.setDragEnabled(true); button.setTransferHandler(new TransferHandler("text")); f.setSize(330, 150); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setLocationRelativeTo(null); f.setVisible(true); }
From source file:TextArea.java
public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextArea area = new JTextArea(); area.setLineWrap(true);// w w w . j a va 2 s . c o m area.setWrapStyleWord(true); area.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8)); f.add(new JScrollPane(area)); f.setSize(new Dimension(350, 300)); f.setLocationRelativeTo(null); f.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { String ITEMS[] = { "Black", "Blue", "Green", "Orange", "Purple", "Red", "White" }; JList jList = new JList(ITEMS); jList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JScrollPane scroll = new JScrollPane(jList); scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); JCheckBox chkEnable = new JCheckBox("Enable", true); chkEnable.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { jList.setEnabled(chkEnable.isSelected()); }/*from w w w . j a v a2 s.c o m*/ }); JFrame f = new JFrame("Colors"); Container contentPane = f.getContentPane(); contentPane.setLayout(new BorderLayout()); contentPane.add(scroll, BorderLayout.CENTER); contentPane.add(chkEnable, BorderLayout.NORTH); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setSize(180, 220); f.setLocationRelativeTo(null); f.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextPane ta = new JTextPane(); ta.setContentType("text/html"); ta.setText("<HTML><BODY><CODE> import java.io.*; <br> public class MyIO{}</CODE><br></BODY></HTML>"); JScrollPane jsp = new JScrollPane(ta); f.getContentPane().add(jsp);// ww w . j a v a 2 s .c o m f.setSize(300, 200); f.setLocationRelativeTo(null); f.setVisible(true); }
From source file:Main.java
public static void main(String argv[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String testStr = "Paste text here."; JTextArea wrapArea = new JTextArea(testStr, 20, 40); wrapArea.setLineWrap(true);/*from w w w.j a v a2 s. c o m*/ wrapArea.setWrapStyleWord(true); wrapArea.setCaretPosition(testStr.length()); frame.add(new JScrollPane(wrapArea)); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); }