Example usage for javax.swing JFrame add

List of usage examples for javax.swing JFrame add

Introduction

In this page you can find the example usage for javax.swing JFrame add.

Prototype

public Component add(Component comp) 

Source Link

Document

Appends the specified component to the end of this container.

Usage

From source file:Main.java

public static void main(String[] args) {
    JTextArea textArea = new JTextArea(10, 30);
    AbstractDocument doc = (AbstractDocument) textArea.getDocument();
    doc.setDocumentFilter(new EndOfLineFilter());

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(new JScrollPane(textArea));
    frame.pack();/*from w  ww.  ja va  2s .c  om*/
    frame.setVisible(true);
}

From source file:JTableSortDemo.java

public static void main(String[] args) {
    Object[][] data = { { "A", 5 }, { "B", 2 }, { "C", 4 }, { "D", 8 } };
    String columnNames[] = { "Item", "Value" };
    TableModel model = new DefaultTableModel(data, columnNames) {
        public Class<?> getColumnClass(int column) {
            return getValueAt(0, column).getClass();
        }/*  w w w . java  2s  . c om*/
    };
    JTable table = new JTable(model);

    TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model);
    table.setRowSorter(sorter);

    JScrollPane scrollPane = new JScrollPane(table);
    JFrame frame = new JFrame("Sorting Table");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(scrollPane);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(new Main());
    frame.setSize(200, 200);/*from w w w .  j  av a  2s .co  m*/
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] argv) {
    JEditorPane jep = new JEditorPane();
    jep.setContentType("text/html");
    StringBuilder sb = new StringBuilder();
    sb.append("<b>Welcome</b>:<br><hr>");
    for (int i = 1; i <= 3; i++) {
        sb.append(create(i));//from w  w w  . j  a  v  a  2s.  co  m
    }
    sb.append("<hr>");
    jep.setText(sb.toString());
    jep.setEditable(false);
    jep.addHyperlinkListener(e -> {
        if (HyperlinkEvent.EventType.ACTIVATED.equals(e.getEventType())) {
            System.out.println(e.getURL());
            Desktop desktop = Desktop.getDesktop();
            try {
                desktop.browse(e.getURL().toURI());
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    });

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.add(jep);
    f.pack();
    f.setVisible(true);
}

From source file:JapaneseCalendar.java

public static void main(String[] a) {
    JFrame f = new JFrame();

    f.add(new JapaneseCalendar());
    f.pack();/*  w  w w .jav  a 2s.c  o m*/
    f.setVisible(true);
}

From source file:Textures.java

public static void main(String[] args) {
    Textures rects = new Textures();
    JFrame frame = new JFrame("Textures");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(rects);
    frame.setSize(360, 210);/*  w  w  w  .j  ava2 s  .com*/
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame("EditorPaneScroll");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(new Main());
    frame.pack();/*from  w w w .  j  a v  a2s .  com*/
    frame.setLocationByPlatform(true);
    frame.setVisible(true);
}

From source file:WindowEventHandler.java

public static void main(String[] args) {
    JFrame frame = new JFrame("Swing Frame");

    JLabel label = new JLabel("This is a Swing frame", JLabel.CENTER);

    frame.add(label);

    frame.addWindowListener(new WindowEventHandler());
    frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    frame.setSize(350, 200); // width=350, height=200
    frame.setVisible(true); // Display the frame
}

From source file:Main.java

public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        @Override/*  www  . j  av  a  2s . c o m*/
        public void run() {
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.add(new MyPanel());
            f.pack();
            f.setVisible(true);
        }
    });
}

From source file:Main.java

public static void main(String[] args) {
    JButton btnA = new JButton("A");
    JButton btnB = new JButton("B");

    btnA.setPreferredSize(new Dimension(50, 25));
    btnB.setPreferredSize(new Dimension(100, 25));

    JPanel btnAPanel = new JPanel();
    JPanel btnBPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    btnAPanel.add(btnA);//w  w w .  ja  va  2 s. co m
    btnBPanel.add(btnB);

    JPanel topPanel = new JPanel(new GridLayout(1, 0));
    topPanel.add(new JLabel("hi"));
    topPanel.add(btnAPanel);
    topPanel.add(btnBPanel);

    JPanel mainPanel = new JPanel(new BorderLayout());
    mainPanel.add(topPanel, BorderLayout.NORTH);

    mainPanel.setPreferredSize(new Dimension(400, 300));

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(mainPanel);
    frame.pack();
    frame.setVisible(true);
}