List of usage examples for javax.swing JPanel setLayout
public void setLayout(LayoutManager mgr)
From source file:net.redstonelamp.gui.RedstoneLampGUI.java
public static void main(String[] args) { JFrame frame = new JFrame("RedstoneLamp"); frame.setLayout(new GridLayout(2, 1)); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); JLabel label = new JLabel("RedstoneLamp"); label.setHorizontalAlignment(SwingConstants.CENTER); frame.add(label);//from w w w .j a va 2s. c om JPanel lowPanel = new JPanel(); JPanel left = new JPanel(); left.setLayout(new BoxLayout(left, BoxLayout.Y_AXIS)); lowPanel.add(left); JPanel right = new JPanel(); right.setLayout(new BoxLayout(right, BoxLayout.Y_AXIS)); lowPanel.add(right); JButton openButton = new JButton("Open server at..."); openButton.addActionListener(e -> { JFileChooser chooser = new JFileChooser(new File(".")); chooser.setDialogTitle("Select RedstoneLamp server home"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setAcceptAllFileFilterUsed(false); int action = chooser.showOpenDialog(frame); if (action == JFileChooser.APPROVE_OPTION) { File selected = chooser.getSelectedFile(); File jar = new File("RedstoneLamp.jar"); if (!jar.isFile()) { int result = JOptionPane.showConfirmDialog(frame, "Could not find RedstoneLamp installation. " + "Would you like to install RedstoneLamp there?"); if (result == JOptionPane.YES_OPTION) { installCallback(frame, selected); } return; } frame.dispose(); addHistory(selected); currentRoot = new ServerActivity(selected); } }); right.add(openButton); JButton installButton = new JButton("Install server at..."); installButton.addActionListener(e -> { JFileChooser chooser = new JFileChooser("."); chooser.setDialogTitle("Select directory to install server in"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setAcceptAllFileFilterUsed(false); int action = chooser.showSaveDialog(frame); if (action == JFileChooser.APPROVE_OPTION) { File selected = chooser.getSelectedFile(); File jar = new File("RedstoneLamp.jar"); if (jar.isFile()) { int result = JOptionPane.showConfirmDialog(frame, "A RedstoneLamp jar installation is present. " + "Are you sure you want to reinstall RedstoneLamp there?"); if (result == JOptionPane.NO_OPTION) { frame.dispose(); addHistory(selected); currentRoot = new ServerActivity(selected); return; } } installCallback(frame, selected); } }); frame.add(lowPanel); frame.pack(); Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize(); frame.setLocation(dimension.width / 2 - frame.getSize().width / 2, dimension.height / 2 - frame.getSize().height / 2); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) { JFrame demo = new JFrame("GridBag demo, to center a component"); JPanel parentPanel = new JPanel(); GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints constraints = new GridBagConstraints(); constraints.fill = GridBagConstraints.CENTER; gridbag.setConstraints(parentPanel, constraints); parentPanel.setLayout(gridbag); Label centerLabel = new Label(" AAA..."); parentPanel.add(centerLabel);/*w w w . ja v a2 s .co m*/ demo.add(parentPanel); demo.setSize(500, 500); demo.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame(); JPanel topPane = new JPanel(); JPanel midPane = new JPanel(); JPanel panesHolder = new JPanel(); JLabel label = new JLabel("Top label"); JTextField field = new JTextField(); field.setColumns(5);/*from w w w .j a va 2 s . com*/ topPane.setLayout(new FlowLayout()); midPane.setLayout(new GridLayout(3, 2)); topPane.add(label); topPane.add(field); midPane.add(new JButton("Button 1")); midPane.add(new JButton("Button 2")); midPane.add(new JButton("A")); midPane.add(new JButton("H")); midPane.add(new JButton("I")); midPane.add(new JButton("T")); panesHolder.setLayout(new BoxLayout(panesHolder, BoxLayout.Y_AXIS)); panesHolder.add(topPane); panesHolder.add(midPane); frame.add(panesHolder); frame.setSize(400, 300); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); JPanel panel = new JPanel(); JScrollPane listScrollPane = new JScrollPane(); String[] stringArray = { "Testing", "This", "Stuff" }; JList<String> rowList = new JList<>(stringArray); rowList.setVisibleRowCount(2);//from w w w. java 2s. co m listScrollPane.setViewportView(rowList); panel.setLayout(new BorderLayout()); panel.add(listScrollPane); frame.add(panel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); }
From source file:moviedatas.MovieDatas.java
public static void main(String[] args) { FilterController fpc = new FilterController(); SortController spc = new SortController(); //1. Create the frame. JFrame frame = new JFrame("Movies Open Datas by Harp-e"); frame.setPreferredSize(new Dimension(1280, 800)); //2. Optional: What happens when the frame closes? frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); MovieListView movieListView = new MovieListView(); JPanel movieListPanel = movieListView.createViewPanel(); TitledBorder moviesTitle;/*from w ww.j av a 2 s. c o m*/ moviesTitle = BorderFactory.createTitledBorder("Movies"); movieListPanel.setBorder(moviesTitle); //3. Create components and put them in the frame. //---------------------------------------------------------------------- // Sort & Filter panel (right) //---------------------------------------------------------------------- SortPanelView sortFilterView = new SortPanelView(); FilterPanelView filterPanelView = new FilterPanelView(); JPanel sortPanel = sortFilterView.createSortPanel(); JPanel filterPanel = filterPanelView.createFilterPanel(); JPanel sortFilterPanel = new JPanel(); sortFilterPanel.setLayout(new BoxLayout(sortFilterPanel, BoxLayout.PAGE_AXIS)); sortFilterPanel.add(sortPanel); sortFilterPanel.add(filterPanel); frame.getContentPane().add(sortFilterPanel, BorderLayout.WEST); //---------------------------------------------------------------------- // Movie Info Panel (left) //---------------------------------------------------------------------- MovieInfoController movieInfoController = new MovieInfoController(); JPanel movieInfoView = movieInfoController.initView(); TitledBorder infoTitle; infoTitle = BorderFactory.createTitledBorder("Informations"); movieInfoView.setBorder(infoTitle); //---------------------------------------------------------------------- // Movie List Panel (middle) //---------------------------------------------------------------------- JPanel listPanel = new JPanel(); listPanel.setLayout(new BorderLayout()); listPanel.setPreferredSize(new Dimension(1280, 400)); listPanel.add(sortFilterPanel, BorderLayout.WEST); listPanel.add(movieInfoView, BorderLayout.EAST); listPanel.add(movieListPanel, BorderLayout.CENTER); frame.getContentPane().add(listPanel, BorderLayout.NORTH); //---------------------------------------------------------------------- // Charts Panel (bottom) //---------------------------------------------------------------------- JPanel chartPanel = new JPanel(); // Spider chart Panel //______________________________________________________________________ // Create the panel JPanel spiderPanel = new JPanel(); // Create the view SpiderChartView spiderChartView = new SpiderChartView(); // Create a tilte TitledBorder spiderTitle; // Put a border around the title spiderTitle = BorderFactory.createTitledBorder("Spider chart"); // Put the border on the panel spiderPanel.setBorder(spiderTitle); // Put the view on the panel spiderPanel.add(spiderChartView.initView()); // Put the spider panel on the global panel chartPanel.add(spiderPanel); //______________________________________________________________________ // Bar chart Panel //______________________________________________________________________ JPanel barPanel = new JPanel(); BarChartView barChartView = new BarChartView(); TitledBorder barTitle; barTitle = BorderFactory.createTitledBorder("Bar chart"); barPanel.setBorder(barTitle); barPanel.add(barChartView.initView()); chartPanel.add(barPanel); //______________________________________________________________________ // Global chart Panel //______________________________________________________________________ JPanel globalChartPanel = new JPanel(); GlobalChart globalChartView = new GlobalChart(); TitledBorder globalTitle; globalTitle = BorderFactory.createTitledBorder("Global chart"); globalChartPanel.setBorder(globalTitle); globalChartPanel.add(globalChartView.initView()); chartPanel.add(globalChartPanel); //______________________________________________________________________ frame.getContentPane().add(chartPanel, BorderLayout.CENTER); //---------------------------------------------------------------------- //4. Size the frame. frame.pack(); //5. Show it. frame.setVisible(true); //ArrayList<Movie> movies = new ArrayList<>(); //FilterController.filter(10,SortController.byTitle(movies)); }
From source file:Main.java
public static void main(String[] args) { JPanel panel1 = new JPanel(); JPanel panel2 = new JPanel(); JButton button = new JButton(); Main f = null;/*from www. ja va2 s .co m*/ f = new Main(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setSize(700, 400); panel1.setLayout(new BorderLayout()); panel1.setForeground(Color.white); button.setText("Convert"); panel1.add(button, BorderLayout.SOUTH); f.setContentPane(panel1); f.setVisible(true); f1 = new Main(); f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f1.setSize(457, 100); f1.setTitle("Conversion Progress"); f1.setLocationRelativeTo(null); panel2.setLayout(new BorderLayout()); panel2.setForeground(Color.white); JProgressBar progressBar = new JProgressBar(); progressBar.setValue(35); progressBar.setStringPainted(true); panel2.add(progressBar, BorderLayout.SOUTH); f1.setContentPane(panel2); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { f1.setVisible(true); } }); }
From source file:DisplayMessage.java
public static void main(String[] args) { /*/*w w w .ja v a 2s .c om*/ * Step 1: Create the components */ JLabel msgLabel = new JLabel(); // Component to display the question JButton yesButton = new JButton(); // Button for an affirmative response JButton noButton = new JButton(); // Button for a negative response /* * Step 2: Set properties of the components */ msgLabel.setText(args[0]); // The msg to display msgLabel.setBorder(new EmptyBorder(10, 10, 10, 10)); // A 10-pixel margin yesButton.setText((args.length >= 2) ? args[1] : "Yes"); // Text for Yes button noButton.setText((args.length >= 3) ? args[2] : "No"); // Text for no button /* * Step 3: Create containers to hold the components */ JFrame win = new JFrame("Message"); // The main application window JPanel buttonbox = new JPanel(); // A container for the two buttons /* * Step 4: Specify LayoutManagers to arrange components in the containers */ win.getContentPane().setLayout(new BorderLayout()); // layout on borders buttonbox.setLayout(new FlowLayout()); // layout left-to-right /* * Step 5: Add components to containers, with optional layout constraints */ buttonbox.add(yesButton); // add yes button to the panel buttonbox.add(noButton); // add no button to the panel // add JLabel to window, telling the BorderLayout to put it in the middle win.getContentPane().add(msgLabel, "Center"); // add panel to window, telling the BorderLayout to put it at the bottom win.getContentPane().add(buttonbox, "South"); /* * Step 6: Arrange to handle events in the user interface. */ yesButton.addActionListener(new ActionListener() { // Note: inner class // This method is called when the Yes button is clicked. public void actionPerformed(ActionEvent e) { System.exit(0); } }); noButton.addActionListener(new ActionListener() { // Note: inner class // This method is called when the No button is clicked. public void actionPerformed(ActionEvent e) { System.exit(1); } }); /* * Step 7: Display the GUI to the user */ win.pack(); // Set the size of the window based its children's sizes. win.show(); // Make the window visible. }
From source file:com.amazonaws.services.kinesis.leases.impl.LeaseCoordinatorExerciser.java
public static void main(String[] args) throws InterruptedException, DependencyException, InvalidStateException, ProvisionedThroughputException, IOException { int numCoordinators = 9; int numLeases = 73; int leaseDurationMillis = 10000; int epsilonMillis = 100; AWSCredentialsProvider creds = new DefaultAWSCredentialsProviderChain(); AmazonDynamoDBClient ddb = new AmazonDynamoDBClient(creds); ILeaseManager<KinesisClientLease> leaseManager = new KinesisClientLeaseManager("nagl_ShardProgress", ddb); if (leaseManager.createLeaseTableIfNotExists(10L, 50L)) { LOG.info("Waiting for newly created lease table"); if (!leaseManager.waitUntilLeaseTableExists(10, 300)) { LOG.error("Table was not created in time"); return; }/*from w ww. j a v a 2 s . co m*/ } CWMetricsFactory metricsFactory = new CWMetricsFactory(creds, "testNamespace", 30 * 1000, 1000); final List<LeaseCoordinator<KinesisClientLease>> coordinators = new ArrayList<LeaseCoordinator<KinesisClientLease>>(); for (int i = 0; i < numCoordinators; i++) { String workerIdentifier = "worker-" + Integer.toString(i); LeaseCoordinator<KinesisClientLease> coord = new LeaseCoordinator<KinesisClientLease>(leaseManager, workerIdentifier, leaseDurationMillis, epsilonMillis, metricsFactory); coordinators.add(coord); } leaseManager.deleteAll(); for (int i = 0; i < numLeases; i++) { KinesisClientLease lease = new KinesisClientLease(); lease.setLeaseKey(Integer.toString(i)); lease.setCheckpoint(new ExtendedSequenceNumber("checkpoint")); leaseManager.createLeaseIfNotExists(lease); } final JFrame frame = new JFrame("Test Visualizer"); frame.setPreferredSize(new Dimension(800, 600)); final JPanel panel = new JPanel(new GridLayout(coordinators.size() + 1, 0)); final JLabel ticker = new JLabel("tick"); panel.add(ticker); frame.getContentPane().add(panel); final Map<String, JLabel> labels = new HashMap<String, JLabel>(); for (final LeaseCoordinator<KinesisClientLease> coord : coordinators) { JPanel coordPanel = new JPanel(); coordPanel.setLayout(new BoxLayout(coordPanel, BoxLayout.X_AXIS)); final Button button = new Button("Stop " + coord.getWorkerIdentifier()); button.setMaximumSize(new Dimension(200, 50)); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { if (coord.isRunning()) { coord.stop(); button.setLabel("Start " + coord.getWorkerIdentifier()); } else { try { coord.start(); } catch (LeasingException e) { LOG.error(e); } button.setLabel("Stop " + coord.getWorkerIdentifier()); } } }); coordPanel.add(button); JLabel label = new JLabel(); coordPanel.add(label); labels.put(coord.getWorkerIdentifier(), label); panel.add(coordPanel); } frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); new Thread() { // Key is lease key, value is green-ness as a value from 0 to 255. // Great variable name, huh? private Map<String, Integer> greenNesses = new HashMap<String, Integer>(); // Key is lease key, value is last owning worker private Map<String, String> lastOwners = new HashMap<String, String>(); @Override public void run() { while (true) { for (LeaseCoordinator<KinesisClientLease> coord : coordinators) { String workerIdentifier = coord.getWorkerIdentifier(); JLabel label = labels.get(workerIdentifier); List<KinesisClientLease> asgn = new ArrayList<KinesisClientLease>(coord.getAssignments()); Collections.sort(asgn, new Comparator<KinesisClientLease>() { @Override public int compare(KinesisClientLease arg0, KinesisClientLease arg1) { return arg0.getLeaseKey().compareTo(arg1.getLeaseKey()); } }); StringBuilder builder = new StringBuilder(); builder.append("<html>"); builder.append(workerIdentifier).append(":").append(asgn.size()).append(" "); for (KinesisClientLease lease : asgn) { String leaseKey = lease.getLeaseKey(); String lastOwner = lastOwners.get(leaseKey); // Color things green when they switch owners, decay the green-ness over time. Integer greenNess = greenNesses.get(leaseKey); if (greenNess == null || lastOwner == null || !lastOwner.equals(lease.getLeaseOwner())) { greenNess = 200; } else { greenNess = Math.max(0, greenNess - 20); } greenNesses.put(leaseKey, greenNess); lastOwners.put(leaseKey, lease.getLeaseOwner()); builder.append(String.format("<font color=\"%s\">%03d</font>", String.format("#00%02x00", greenNess), Integer.parseInt(leaseKey))).append(" "); } builder.append("</html>"); label.setText(builder.toString()); label.revalidate(); label.repaint(); } if (ticker.getText().equals("tick")) { ticker.setText("tock"); } else { ticker.setText("tick"); } try { Thread.sleep(200); } catch (InterruptedException e) { } } } }.start(); frame.pack(); frame.setVisible(true); for (LeaseCoordinator<KinesisClientLease> coord : coordinators) { coord.start(); } }
From source file:brainflow.app.presentation.controls.FileObjectGroupSelector.java
public static void main(String[] args) { try {/*from w w w .j a v a 2 s. c om*/ com.jidesoft.utils.Lm.verifyLicense("UIN", "BrainFlow", "S5XiLlHH0VReaWDo84sDmzPxpMJvjP3"); //com.jidesoft.plaf.LookAndFeelFactory.installDefaultLookAndFeel(); //LookAndFeelFactory.installJideExtension(LookAndFeelFactory.OFFICE2007_STYLE); UIManager.setLookAndFeel(new NimbusLookAndFeel()); JFrame jf = new JFrame(); FileObjectGroupSelector selector = new FileObjectGroupSelector( VFS.getManager().resolveFile("c:/javacode")); ButtonPanel buttonPanel = new ButtonPanel(SwingConstants.RIGHT); buttonPanel.setSizeConstraint(ButtonPanel.NO_LESS_THAN); JButton okButton = new JButton("OK"); JButton resetButton = new JButton("Cancel"); buttonPanel.addButton(okButton, ButtonPanel.AFFIRMATIVE_BUTTON); buttonPanel.addButton(resetButton, ButtonPanel.CANCEL_BUTTON); buttonPanel.setBorder(BorderFactory.createEmptyBorder(0, 8, 8, 8)); JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); panel.add(selector, BorderLayout.CENTER); panel.add(buttonPanel, BorderLayout.SOUTH); panel.setMinimumSize(new Dimension(800, 100)); jf.add(panel, BorderLayout.CENTER); jf.pack(); jf.setVisible(true); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame(); JPanel panel = new JPanel(); JTextPane textPane = new JTextPane(); JTextField tf = new JTextField("is"); String word = ""; Highlighter highlighter = new UnderlineHighlighter(null); textPane.setHighlighter(highlighter); textPane.setText("This is a test"); panel.setLayout(new BorderLayout()); panel.add(new JLabel("Enter word, then press ENTER key: "), "West"); panel.add(tf, "Center"); final WordSearcher searcher = new WordSearcher(textPane); tf.addActionListener(e -> {/*from w ww. j a v a 2 s . c o m*/ String w = tf.getText().trim(); int offset = searcher.search(w); if (offset == -1) { return; } try { textPane.scrollRectToVisible(textPane.modelToView(offset)); } catch (BadLocationException ex) { } }); textPane.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent evt) { searcher.search(word); } @Override public void removeUpdate(DocumentEvent evt) { searcher.search(word); } @Override public void changedUpdate(DocumentEvent evt) { } }); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(panel, "South"); f.add(new JScrollPane(textPane), "Center"); f.setSize(400, 400); f.setVisible(true); }