List of usage examples for javax.swing JFrame setBounds
public void setBounds(int x, int y, int width, int height)
The width or height values are automatically enlarged if either is less than the minimum size as specified by previous call to setMinimumSize .
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setLayout(new BorderLayout()); JLabel label = new JLabel("<html>" + "<img src=\"" + Main.class.getResource("/resource/path/to/image1.jpg") + "\">" + "<img src=\"" + Main.class.getResource("/resource/path/to/image2.jpg") + "\">" + "The text</html>"); frame.add(label, BorderLayout.CENTER); frame.setBounds(100, 100, 200, 100); frame.setVisible(true);/* www. j av a 2 s . c om*/ }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); contentPane.setLayout(null);//from w w w. j a va2 s . com JButton b1 = new JButton("Button"); JButton b2 = new JButton("2"); contentPane.add(b1); contentPane.add(b2); b1.setBounds(10, 10, 100, 20); b2.setBounds(120, 10, 150, 40); frame.setBounds(0, 0, 350, 100); frame.setVisible(true); }
From source file:com.joey.software.memoryToolkit.MemoryUsagePanel.java
/** * Entry point for the sample application. * //from w ww. ja v a 2 s . c o m * @param args * ignored. */ public static void main(String[] args) { JFrame frame = new JFrame("Memory Usage Demo"); MemoryUsagePanel panel = new MemoryUsagePanel(500, 20); frame.getContentPane().add(panel, BorderLayout.CENTER); frame.setBounds(200, 120, 600, 280); frame.setVisible(true); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { System.exit(0); } }); panel.startUpdating(); byte[][][] data = new byte[1024][1024][10]; }
From source file:UndoExample1.java
public static void main(String[] args) { try {// w ww . j a va 2 s .com UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } JFrame f = new UndoExample1(); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { System.exit(0); } }); f.setSize(250, 300); f.setVisible(true); // Create and show a frame monitoring undoable edits JFrame undoMonitor = new JFrame("Undo Monitor"); final JTextArea textArea = new JTextArea(); textArea.setEditable(false); undoMonitor.getContentPane().add(new JScrollPane(textArea)); undoMonitor.setBounds(f.getLocation().x + f.getSize().width, f.getLocation().y, 400, 200); undoMonitor.setVisible(true); pane.getDocument().addUndoableEditListener(new UndoableEditListener() { public void undoableEditHappened(UndoableEditEvent evt) { UndoableEdit edit = evt.getEdit(); textArea.append(edit.getPresentationName() + "(" + edit.toString() + ")\n"); } }); // Create and show a frame monitoring document edits JFrame editMonitor = new JFrame("Edit Monitor"); final JTextArea textArea2 = new JTextArea(); textArea2.setEditable(false); editMonitor.getContentPane().add(new JScrollPane(textArea2)); editMonitor.setBounds(undoMonitor.getLocation().x, undoMonitor.getLocation().y + undoMonitor.getSize().height, 400, 200); editMonitor.setVisible(true); pane.getDocument().addDocumentListener(new DocumentListener() { public void changedUpdate(DocumentEvent evt) { textArea2.append("Attribute change\n"); } public void insertUpdate(DocumentEvent evt) { textArea2.append("Text insertion\n"); } public void removeUpdate(DocumentEvent evt) { textArea2.append("Text removal\n"); } }); }
From source file:Main.java
public static void main(String[] args) { JPanel statusBar = new JPanel(new FlowLayout(FlowLayout.LEFT)); statusBar.setBorder(new CompoundBorder(new LineBorder(Color.DARK_GRAY), new EmptyBorder(4, 4, 4, 4))); final JLabel status = new JLabel(); statusBar.add(status);/*from w ww. j a va 2 s . co m*/ JLabel content = new JLabel("Content in the middle"); content.setHorizontalAlignment(JLabel.CENTER); final JFrame frame = new JFrame("Test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(content); frame.add(statusBar, BorderLayout.SOUTH); frame.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { status.setText(frame.getWidth() + "x" + frame.getHeight()); } }); frame.setBounds(20, 20, 200, 200); frame.setVisible(true); }
From source file:UndoExample5.java
public static void main(String[] args) { try {/*from ww w. j a va 2 s. co m*/ UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } JFrame f = new UndoExample5(); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { System.exit(0); } }); f.setSize(250, 300); f.setVisible(true); // Create and show a frame monitoring undoable edits JFrame undoMonitor = new JFrame("Undo Monitor"); final JTextArea textArea = new JTextArea(); textArea.setEditable(false); undoMonitor.getContentPane().add(new JScrollPane(textArea)); undoMonitor.setBounds(f.getLocation().x + f.getSize().width, f.getLocation().y, 400, 200); undoMonitor.setVisible(true); pane.getDocument().addUndoableEditListener(new UndoableEditListener() { public void undoableEditHappened(UndoableEditEvent evt) { UndoableEdit edit = evt.getEdit(); textArea.append(edit.getPresentationName() + "(" + edit.toString() + ")\n"); } }); // Create and show a frame monitoring document edits JFrame editMonitor = new JFrame("Edit Monitor"); final JTextArea textArea2 = new JTextArea(); textArea2.setEditable(false); editMonitor.getContentPane().add(new JScrollPane(textArea2)); editMonitor.setBounds(undoMonitor.getLocation().x, undoMonitor.getLocation().y + undoMonitor.getSize().height, 400, 200); editMonitor.setVisible(true); pane.getDocument().addDocumentListener(new DocumentListener() { public void changedUpdate(DocumentEvent evt) { textArea2.append("Attribute change\n"); } public void insertUpdate(DocumentEvent evt) { textArea2.append("Text insertion\n"); } public void removeUpdate(DocumentEvent evt) { textArea2.append("Text removal\n"); } }); }
From source file:com.music.Generator.java
public static void main(String[] args) throws Exception { Score score1 = new Score(); Read.midi(score1, "c:/tmp/gen.midi"); for (Part part : score1.getPartArray()) { System.out.println(part.getInstrument()); }/*w w w . ja v a2 s. c o m*/ new StartupListener().contextInitialized(null); Generator generator = new Generator(); generator.configLocation = "c:/config/music"; generator.maxConcurrentGenerations = 5; generator.init(); UserPreferences prefs = new UserPreferences(); prefs.setElectronic(Ternary.YES); //prefs.setSimpleMotif(Ternary.YES); //prefs.setMood(Mood.MAJOR); //prefs.setDrums(Ternary.YES); //prefs.setClassical(true); prefs.setAccompaniment(Ternary.YES); prefs.setElectronic(Ternary.YES); final ScoreContext ctx = generator.generatePiece(); Score score = ctx.getScore(); for (Part part : score.getPartArray()) { System.out.println(part.getTitle() + ": " + part.getInstrument()); } System.out.println("Metre: " + ctx.getMetre()[0] + "/" + ctx.getMetre()[1]); System.out.println(ctx); Write.midi(score, "c:/tmp/gen.midi"); new Thread(new Runnable() { @Override public void run() { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setBounds(0, 0, 500, 500); frame.setVisible(true); Part part = ctx.getParts().get(PartType.MAIN); Note[] notes = part.getPhrase(0).getNoteArray(); List<Integer> pitches = new ArrayList<Integer>(); for (Note note : notes) { if (!note.isRest()) { pitches.add(note.getPitch()); } } GraphicsPanel gp = new GraphicsPanel(pitches); frame.setContentPane(gp); } }).start(); DecimalFormat df = new DecimalFormat("#.##"); for (Part part : score.getPartArray()) { StringBuilder sb = new StringBuilder(); printStatistics(ctx, part); System.out.println("------------ " + part.getTitle() + "-----------------"); Phrase[] phrases = part.getPhraseArray(); for (Phrase phr : phrases) { if (phr instanceof ExtendedPhrase) { sb.append("Contour=" + ((ExtendedPhrase) phr).getContour() + " "); } double measureSize = 0; int measures = 0; double totalLength = 0; List<String> pitches = new ArrayList<String>(); List<String> lengths = new ArrayList<String>(); System.out.println("((Phrase notes: " + phr.getNoteArray().length + ")"); for (Note note : phr.getNoteArray()) { if (!note.isRest()) { int degree = 0; if (phr instanceof ExtendedPhrase) { degree = Arrays.binarySearch(((ExtendedPhrase) phr).getScale().getDefinition(), note.getPitch() % 12); } pitches.add(String.valueOf(note.getPitch() + " (" + degree + ") ")); } else { pitches.add(" R "); } lengths.add(df.format(note.getRhythmValue())); measureSize += note.getRhythmValue(); totalLength += note.getRhythmValue(); ; if (measureSize >= ctx.getNormalizedMeasureSize()) { pitches.add(" || "); lengths.add(" || " + (measureSize > ctx.getNormalizedMeasureSize() ? "!" : "")); measureSize = 0; measures++; } } sb.append(pitches.toString() + "\r\n"); sb.append(lengths.toString() + "\r\n"); if (part.getTitle().equals(PartType.MAIN.getTitle())) { sb.append("\r\n"); } System.out.println("Phrase measures: " + measures); System.out.println("Phrase length: " + totalLength); } System.out.println(sb.toString()); } MutingPrintStream.ignore.set(true); Write.midi(score, "c:/tmp/gen.midi"); MutingPrintStream.ignore.set(null); Play.midi(score); generator.toMp3(FileUtils.readFileToByteArray(new File("c:/tmp/gen.midi"))); }
From source file:Main.java
public static void main(String[] args) { final JFrame parent1 = new JFrame("Parent Frame 1"); parent1.setLayout(new FlowLayout()); parent1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button = new JButton("Application modal dialog"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JDialog dialog = new JDialog(parent1, "Application-Modal Dialog", Dialog.ModalityType.APPLICATION_MODAL); dialog.setBounds(200, 150, 200, 150); dialog.setVisible(true);// www. ja v a2 s. co m } }); parent1.add(button); parent1.setBounds(100, 100, 200, 150); parent1.setVisible(true); JFrame parent2 = new JFrame("Parent Frame 2"); parent2.setBounds(500, 100, 200, 150); parent2.setVisible(true); }
From source file:dk.dma.epd.common.prototype.gui.notification.ChatServicePanel.java
/** * Test method//from www .j av a2s . c om */ public static void main(String... args) { JFrame f = new JFrame("Chat service panel test"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setBounds(100, 100, 300, 400); ChatServicePanel p = new ChatServicePanel(false) { private static final long serialVersionUID = 1L; @Override protected void sendChatMessage() { MaritimeText chatMessage = new MaritimeText(); chatMessage.setMsg(messageText.getText()); EPDChatMessage epdChatMessage = new EPDChatMessage(chatMessage, true, Timestamp.now()); chatData.addChatMessage(epdChatMessage); updateChatMessagePanel(); } }; f.getContentPane().add(p); MaritimeId id = new MmsiId(999333333); ChatServiceData chatData = new ChatServiceData(id); long time = System.currentTimeMillis() - 1000L * 60L * 60L * 24L * 10L; // Go back 10 days for (int x = 0; x < 10; x++) { time += Math.random() * 1000L * 60L * 10L; // add 0-10 minutes boolean ownMessage = Math.random() < 0.5; MaritimeText msg = new MaritimeText(); msg.setMsg("hello yourself\nJGsfdkjfhg"); EPDChatMessage epdChatMessage = new EPDChatMessage(msg, ownMessage, Timestamp.create(time)); if (Math.random() < 0.1) { epdChatMessage.setSeverity(MaritimeTextingNotificationSeverity.ALERT); } else if (Math.random() < 0.2) { epdChatMessage.setSeverity(MaritimeTextingNotificationSeverity.WARNING); } chatData.addChatMessage(epdChatMessage); } p.chatData = chatData; p.updateChatMessagePanel(); f.setVisible(true); }
From source file:customize.swing.startMain.java
public static void main(String[] args) { JFrame frame = new JFrame("startMain"); frame.setContentPane(new startMain().panel1); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack();/*from www . j a v a 2 s.c o m*/ frame.setVisible(true); frame.setBounds(500, 300, 983, 587); }