List of usage examples for java.awt Container add
public void add(Component comp, Object constraints)
From source file:Main.java
public Main(String title) { super(title); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = this.getContentPane(); Box editorPaneBox = this.getEditPaneBox(); contentPane.add(editorPaneBox, BorderLayout.CENTER); }
From source file:Main.java
public Main() { JMenuBar bar = new JMenuBar(); JMenu addMenu = new JMenu("Add"); JMenuItem newFrame = new JMenuItem("Internal Frame"); addMenu.add(newFrame);/*from w w w .j a v a2 s.c o m*/ bar.add(addMenu); setJMenuBar(bar); final JDesktopPane theDesktop = new JDesktopPane(); getContentPane().add(theDesktop); newFrame.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JInternalFrame frame = new JInternalFrame("Internal Frame", true, true, true, true); Container c = frame.getContentPane(); MyJPanel panel = new MyJPanel(); c.add(panel, BorderLayout.CENTER); frame.setSize(200, 200); frame.setOpaque(true); theDesktop.add(frame); } }); setSize(500, 400); setVisible(true); }
From source file:ModelJTable.java
public ModelJTable() { super();// w ww . j a va2s. c o m model = new DefaultTableModel(); model.addColumn("First Name"); model.addColumn("Last Name"); model.addColumn("Years"); String[] socrates = { "Socrates", "", "469-399 B.C." }; model.addRow(socrates); String[] plato = { "Plato", "", "428-347 B.C." }; model.addRow(plato); String[] aquinas = { "Thomas", "Aquinas", "1225-1274" }; model.addRow(aquinas); String[] kierkegaard = { "Soren", "Kierkegaard", "1813-1855" }; model.addRow(kierkegaard); String[] kant = { "Immanuel", "Kant", "1724-1804" }; model.addRow(kant); String[] nietzsche = { "Friedrich", "Nietzsche", "1844-1900" }; model.addRow(nietzsche); String[] arendt = { "Hannah", "Arendt", "1906-1975" }; model.addRow(arendt); table = new JTable(model); JButton addButton = new JButton("Add Philosopher"); addButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { String[] philosopher = { "", "", "" }; model.addRow(philosopher); } }); JButton removeButton = new JButton("Remove Selected Philosopher"); removeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { model.removeRow(table.getSelectedRow()); } }); JPanel inputPanel = new JPanel(); inputPanel.add(addButton); inputPanel.add(removeButton); Container container = getContentPane(); container.add(new JScrollPane(table), BorderLayout.CENTER); container.add(inputPanel, BorderLayout.NORTH); setDefaultCloseOperation(EXIT_ON_CLOSE); setSize(400, 300); setVisible(true); }
From source file:QandE.SwingApp1.java
void createGUI(JFrame f) { startButton = new JButton("Start"); stopButton = new JButton("Stop"); label = new JLabel("Press Start.", JLabel.CENTER); Container c = f.getContentPane(); //Use the content pane's default BorderLayout layout manager. c.add(startButton, BorderLayout.WEST); c.add(stopButton, BorderLayout.EAST); c.add(label, BorderLayout.SOUTH); }
From source file:PersisTest.java
public PersisTest(String pathname) { super("Save Me"); setDefaultCloseOperation(EXIT_ON_CLOSE); this.pathname = pathname; // Build the GUI. Make this object a listener for all actions. JPanel pan = new JPanel(); clearBtn = new JButton("Clear"); clearBtn.addActionListener(this); pan.add(clearBtn);/* w w w . j a va 2s . co m*/ saveBtn = new JButton("Save"); saveBtn.addActionListener(this); pan.add(saveBtn); restoreBtn = new JButton("Restore"); restoreBtn.addActionListener(this); pan.add(restoreBtn); quitBtn = new JButton("Quit"); quitBtn.addActionListener(this); pan.add(quitBtn); Container c = getContentPane(); c.add(pan, BorderLayout.NORTH); c.add(new ClickPanel(), BorderLayout.CENTER); setSize(350, 200); }
From source file:LongListTest.java
public LongListFrame() { setTitle("LongListTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); wordList = new JList(new WordListModel(3)); wordList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); wordList.setPrototypeCellValue("www"); JScrollPane scrollPane = new JScrollPane(wordList); JPanel p = new JPanel(); p.add(scrollPane);//from w ww. ja va 2 s .c o m wordList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent evt) { StringBuilder word = (StringBuilder) wordList.getSelectedValue(); setSubject(word.toString()); } }); Container contentPane = getContentPane(); contentPane.add(p, BorderLayout.NORTH); label = new JLabel(prefix + suffix); contentPane.add(label, BorderLayout.CENTER); setSubject("fox"); }
From source file:BoxLayoutTest.java
public BoxLayoutTest() { setTitle("BoxLayoutTest"); setSize(300, 300);/*from www . ja v a 2 s.co m*/ addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); horizontalBox = createBox(true, false); verticalBox = createBox(false, false); horizontalStrutsAndGlueBox = createBox(true, true); verticalStrutsAndGlueBox = createBox(false, true); JPanel panel = new JPanel(); panel.setLayout(new GridLayout(3, 1, 3, 3)); ButtonGroup directionGroup = new ButtonGroup(); horizontalButton = addRadioButton(panel, directionGroup, "Horizontal", true); verticalButton = addRadioButton(panel, directionGroup, "Vertical", false); strutsAndGlueCheckBox = addCheckBox(panel, "Struts and Glue"); Container contentPane = getContentPane(); contentPane.add(panel, "South"); contentPane.add(horizontalBox, "Center"); currentBox = horizontalBox; }
From source file:SplashScreen.java
public SplashScreen(final BufferedImage img) { JPanel panel = new JPanel() { public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g.create(); g2d.drawImage(img, 0, 0, img.getWidth(), img.getHeight(), SplashScreen.this); }//w w w.ja va 2s. com }; panel.setPreferredSize(new Dimension(img.getWidth(), img.getHeight())); Container content = getContentPane(); content.setLayout(new BorderLayout()); content.add(panel, BorderLayout.NORTH); content.add(label = new JLabel(), BorderLayout.CENTER); content.add(bar = new JProgressBar(), BorderLayout.SOUTH); pack(); setLocationRelativeTo(null); }
From source file:Main.java
public SplashScreen() { Container container = getContentPane(); JPanel panel = new JPanel(); panel.setBorder(new EtchedBorder()); container.add(panel, BorderLayout.CENTER); JLabel label = new JLabel("Hello World!"); label.setFont(new Font("Verdana", Font.BOLD, 14)); panel.add(label);/*from w w w. j a va2 s .co m*/ progressBar.setMaximum(PROGBAR_MAX); container.add(progressBar, BorderLayout.SOUTH); pack(); setVisible(true); startProgressBar(); }
From source file:QandE.SwingApp2.java
void createGUI(JFrame f) { startButton = new JButton("Start"); stopButton = new JButton("Stop"); stopButton.setEnabled(false);/*w ww. j a v a2s . c o m*/ label = new JLabel("Press Start.", JLabel.CENTER); Container c = f.getContentPane(); //Use the content pane's default BorderLayout layout manager. c.add(startButton, BorderLayout.WEST); c.add(stopButton, BorderLayout.EAST); c.add(label, BorderLayout.SOUTH); }