List of usage examples for javax.swing JFrame setLocation
@Override public void setLocation(int x, int y)
The method changes the geometry-related data.
From source file:Main.java
/** "main program" method - construct and show */ public static void main(String[] av) { // create a MoreChoices object, tell it to show up JFrame jf = new Main(); jf.setLocation(100, 100); // get away from screen corner, // since on some OSes a main window at 0,0 may be // partly obscured (e.g. notebook with PowerPanel jf.setVisible(true);/*from ww w . ja va 2s . c o m*/ }
From source file:Main.java
public static void main(String[] args) { int TIME_VISIBLE = 3000; JFrame frame1 = new JFrame(); frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame1.setSize(100, 100);//from w w w. j a v a2 s .co m frame1.setLocation(100, 100); JButton button = new JButton("My Button"); frame1.getContentPane().add(button); button.addActionListener(e -> { JOptionPane pane = new JOptionPane("Message", JOptionPane.INFORMATION_MESSAGE); JDialog dialog = pane.createDialog(null, "Title"); dialog.setModal(false); dialog.setVisible(true); new Timer(TIME_VISIBLE, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dialog.setVisible(false); } }).start(); }); frame1.setVisible(true); }
From source file:MainClass.java
public static void main(String[] unused) { JFrame f = new JFrame("FrameIcon"); Image im = Toolkit.getDefaultToolkit().getImage("FrameIcon.gif"); f.setIconImage(im);/*from w w w . j a v a2 s .c o m*/ f.setSize(100, 100); f.setLocation(200, 200); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { String[] headers = { "column 1", "column 2", "column 3", "column 4" }; int cols = 4; int rows = 6; String[][] data = new String[rows][cols]; for (int row = 0; row < rows; row++) { for (int col = 0; col < cols; col++) { data[row][col] = "item " + (row * cols + col + 1); }/*from w ww .j a v a 2 s.c om*/ } JTable table = new JTable(data, headers); DefaultTableCellRenderer renderer = (DefaultTableCellRenderer) table.getDefaultRenderer(String.class); renderer.setHorizontalAlignment(JLabel.RIGHT); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(new JScrollPane(table)); f.setSize(400, 400); f.setLocation(200, 200); f.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) { JTree tree = new JTree(); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); int treeSelectedRows[] = { 3, 1 }; tree.setSelectionRows(treeSelectedRows); TreeSelectionListener treeSelectionListener = new TreeSelectionListener() { @Override/* ww w .j a va 2 s . c o m*/ 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.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new JScrollPane(tree)); frame.setPreferredSize(new Dimension(380, 320)); frame.setLocation(150, 150); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws Exception { int cp = 0;//w w w . j av a 2s. c o m StyledDocument doc; JTextPane jta = new JTextPane(); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); doc = jta.getStyledDocument(); JScrollPane jsp = new JScrollPane(jta); jsp.setPreferredSize(new Dimension(400, 400)); String[] fnt = ge.getAvailableFontFamilyNames(); MutableAttributeSet mas = jta.getInputAttributes(); for (int i = 0; i < fnt.length; i++) { StyleConstants.setBold(mas, false); StyleConstants.setItalic(mas, false); StyleConstants.setFontFamily(mas, fnt[i]); StyleConstants.setFontSize(mas, 16); doc.insertString(cp, fnt[i] + "\n", mas); StyleConstants.setBold(mas, true); doc.insertString(cp, fnt[i] + "bold \n", mas); StyleConstants.setItalic(mas, true); doc.insertString(cp, fnt[i] + "bold and italic\n", mas); StyleConstants.setBold(mas, false); doc.insertString(cp, fnt[i] + "italic\n", mas); } JFrame frm = new JFrame(); frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frm.setLayout(new BorderLayout()); frm.add(jsp, BorderLayout.CENTER); frm.setLocation(100, 100); frm.pack(); frm.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(new CheckCombo().getContent()); f.setSize(300, 160);/*from www. ja va 2s . c om*/ f.setLocation(200, 200); f.setVisible(true); }
From source file:Main.java
public static void main(String args[]) throws BadLocationException { JTextPane textPane1 = new JTextPane(); MutableAttributeSet black = new SimpleAttributeSet(); MutableAttributeSet red = new SimpleAttributeSet(); StyleConstants.setForeground(black, Color.black); StyleConstants.setForeground(red, Color.red); textPane1.setEditorKit(new StyledEditorKit()); doc1 = textPane1.getDocument();//from w ww . j a v a2 s . c om append1("This is a Test!\n"); attribute = red; append1("Hello world! Hello Stackoverflow\n"); attribute = black; append1("the text is black again\n"); StyledDocument styledDocument = textPane1.getStyledDocument(); Element element; JTextPane textPane2 = new JTextPane(); textPane2.setEditorKit(new StyledEditorKit()); doc2 = textPane2.getDocument(); for (int i = 0; i < styledDocument.getLength(); i++) { element = styledDocument.getCharacterElement(i); AttributeSet attributeNew = element.getAttributes(); System.out.println(i); append2(styledDocument.getText(i, 1), attributeNew); } JFrame frame1 = new JFrame(); frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame1.setSize(400, 300); frame1.getContentPane().add(new JScrollPane(textPane1), BorderLayout.CENTER); frame1.setVisible(true); JFrame frame2 = new JFrame(); frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame2.setSize(400, 300); frame2.setLocation(300, 0); frame2.getContentPane().add(new JScrollPane(textPane2), BorderLayout.CENTER); frame2.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); JFrame window = new JFrame(); window.setSize(300, 300);/* w w w . ja va 2 s .com*/ int w = window.getSize().width; int h = window.getSize().height; int x = (dim.width - w) / 2; int y = (dim.height - h) / 2; window.setLocation(x, y); window.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button = new JButton("Button"); frame.add(button);//from ww w .j av a 2s . c om frame.setAlwaysOnTop(true); frame.setSize(500, 500); frame.setLocation(500, 500); button.addActionListener(e -> { JOptionPane optionPane = new JOptionPane("Option Pane"); optionPane.showMessageDialog(frame, "Message!"); }); frame.setVisible(true); }