List of usage examples for javax.swing JFrame setLayout
public void setLayout(LayoutManager manager)
LayoutManager
. From source file:ActionFocusMover.java
public static void main(String args[]) { JFrame frame = new JFrame("Focus Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ActionListener actionListener = new ActionFocusMover(); frame.setLayout(new GridLayout(3, 3)); for (int i = 1; i < 10; i++) { JButton button = new JButton(Integer.toString(i)); button.addActionListener(actionListener); if ((i % 2) != 0) { button.setFocusable(false);/*from ww w . java2s . c om*/ } frame.add(button); } frame.setSize(300, 200); frame.setVisible(true); }
From source file:MouseEnterFocusMover.java
public static void main(String args[]) { JFrame frame = new JFrame("Focus Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); MouseListener mouseListener = new MouseEnterFocusMover(); frame.setLayout(new GridLayout(3, 3)); for (int i = 1; i < 10; i++) { JButton button = new JButton(Integer.toString(i)); button.addMouseListener(mouseListener); if ((i % 2) != 0) { button.setFocusable(false);/*from w w w .j av a 2s . c o m*/ } frame.add(button); } frame.setSize(300, 200); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) { JFrame frame = new JFrame("Range Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new GridLayout(3, 2)); frame.add(new JLabel("Range: 0-255")); JTextField textFieldOne = new JTextField(); Document textDocOne = textFieldOne.getDocument(); DocumentFilter filterOne = new IntegerRangeDocumentFilter(0, 255); ((AbstractDocument) textDocOne).setDocumentFilter(filterOne); frame.add(textFieldOne);/* w w w . j a v a 2s . com*/ frame.setSize(250, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) { JFrame frame = new JFrame(); JButton component1 = new JButton("1"); JButton component2 = new JButton("2"); JButton component3 = new JButton("3"); frame.setLayout(new FlowLayout()); frame.add(component1);//from w ww . j a va 2 s .c om frame.add(component2); frame.add(component3); frame.pack(); frame.setVisible(true); System.out.println(findPrevFocus().getName()); }
From source file:Main.java
public static void main(String[] argv) { JFrame frame = new JFrame(); JButton component1 = new JButton("1"); JButton component2 = new JButton("2"); JButton component3 = new JButton("3"); frame.setLayout(new FlowLayout()); frame.add(component1);/*from w w w .j a v a2 s . c o m*/ frame.add(component2); frame.add(component3); frame.pack(); frame.setVisible(true); System.out.println(findNextFocus().getName()); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JFrame frame = new JFrame(); JButton component1 = new JButton("1"); JButton component2 = new JButton("2"); JButton component3 = new JButton("3"); frame.setLayout(new FlowLayout()); frame.add(component1);/*from w w w .java 2 s. com*/ frame.add(component2); frame.add(component3); InitialFocusSetter.setInitialFocus(frame, component2); frame.pack(); frame.setVisible(true); }
From source file:ButtonFocus.java
public static void main(String args[]) { JFrame frame = new JFrame("Focus Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton focusButton = new JButton("Focused"); JButton notFocusButton = new JButton("Not Focused"); frame.setLayout(new FlowLayout()); frame.add(focusButton);/*from w w w . j a v a 2 s.com*/ frame.add(notFocusButton); frame.setSize(300, 100); frame.setVisible(true); }
From source file:SampleProgress.java
public static void main(String args[]) { JFrame frame = new JFrame("ProgressMonitor Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new GridLayout(0, 1)); JButton startButton = new JButton("Start"); ActionListener startActionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { Component parent = (Component) actionEvent.getSource(); monitor = new ProgressMonitor(parent, "Loading Progress", "Getting Started...", 0, 200); progress = 0;//w w w. j a v a 2 s. c om } }; startButton.addActionListener(startActionListener); frame.add(startButton); JButton increaseButton = new JButton("Manual Increase"); ActionListener increaseActionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { if (monitor == null) return; if (monitor.isCanceled()) { System.out.println("Monitor canceled"); } else { progress += 5; monitor.setProgress(progress); monitor.setNote("Loaded " + progress + " files"); } } }; increaseButton.addActionListener(increaseActionListener); frame.add(increaseButton); JButton autoIncreaseButton = new JButton("Automatic Increase"); ActionListener autoIncreaseActionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { if (monitor != null) { if (timer == null) { timer = new Timer(250, new ActionListener() { public void actionPerformed(ActionEvent e) { if (monitor == null) return; if (monitor.isCanceled()) { System.out.println("Monitor canceled"); timer.stop(); } else { progress += 3; monitor.setProgress(progress); monitor.setNote("Loaded " + progress + " files"); } } }); } timer.start(); } } }; autoIncreaseButton.addActionListener(autoIncreaseActionListener); frame.add(autoIncreaseButton); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JTree tree = new JTree(new TestModel()); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(new JScrollPane(tree)); frame.pack();/*from w w w. j av a 2s . c o m*/ frame.setVisible(true); }
From source file:ws.moor.bt.grapher.Grapher.java
public static void main(String[] args) throws IOException { if (args.length != 1) { System.err.println("Please specify a tab-separated values file"); System.exit(1);//from www .j a v a 2s. c o m } File file = new File(args[0]); final CSVMapCollector collector = new CSVMapCollector( new CSVSkipFilter(new CSVInputStream(new FileInputStream(file)), 0 * 1000)); JFrame window = new JFrame("Grapher"); window.setSize(1100, 800); window.setLayout(new BorderLayout()); final ChartPanel chartPanel = new ChartPanel(null); List<String> possibleNames = collector.getAvailableStreams(); Collections.sort(possibleNames); TreeNode root = convertToTree(possibleNames); final JTree tree = new JTree(root); tree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { List<String> names = new ArrayList<String>(); final TreePath[] paths = tree.getSelectionModel().getSelectionPaths(); if (paths == null) { chartPanel.setChart(null); return; } for (TreePath path : paths) { Object lastPath = path.getLastPathComponent(); if (lastPath instanceof DefaultMutableTreeNode) { Object value = ((DefaultMutableTreeNode) lastPath).getUserObject(); if (value instanceof NodeValue) { names.add(value.toString()); } } } chartPanel.setChart(createChart(collector, names.toArray(new String[names.size()]))); } }); Font font = tree.getFont(); tree.setFont(font.deriveFont(10.0f)); JScrollPane scrollPane = new JScrollPane(tree); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); splitPane.setLeftComponent(scrollPane); splitPane.setRightComponent(chartPanel); splitPane.setDividerLocation(200); window.setContentPane(splitPane); window.setVisible(true); }