Example usage for javax.swing JFrame setVisible

List of usage examples for javax.swing JFrame setVisible

Introduction

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

Prototype

public void setVisible(boolean b) 

Source Link

Document

Shows or hides this Window depending on the value of parameter b .

Usage

From source file:Main.java

public static void main(String[] args) {
    JPanel gui = new JPanel(new BorderLayout());
    String HTML = "<html>" + "<head>" + "<style type=text/css>" + "body {"
            + "  background-image: http://www.java2s.com/style/download.png;" + "  background-repeat:no-repeat;"
            + "  background-position:left top;" + "  background-attachment: scroll;" + "  color: #BBBBBB;" + "}"
            + "</style>" + "</head>" + "<body>" + "<h1>Heading 1</h1>";
    String PARAGRAPH = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean eu nulla urna. Donec sit amet risus nisl, a porta enim. Quisque luctus, ligula eu scelerisque gravida, tellus quam vestibulum urna, ut aliquet sapien purus sed erat. Pellentesque consequat vehicula magna, eu aliquam magna interdum porttitor. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed sollicitudin sapien non leo tempus lobortis. Morbi semper auctor ipsum, a semper quam elementum a. Aliquam eget sem metus.";

    gui.setPreferredSize(new Dimension(400, 100));

    StringBuilder sb = new StringBuilder();
    sb.append(HTML);// w w  w.  j  a  v a2s  . c  o m
    for (int ii = 0; ii < 10; ii++) {
        sb.append("<h2>Header 2</h2>");
        sb.append(PARAGRAPH);
    }
    JEditorPane jep = new JEditorPane();
    jep.setOpaque(false);
    jep.setContentType("text/html");
    jep.setText(sb.toString());
    JScrollPane jsp = new JScrollPane(jep) {
        BufferedImage bg = new BufferedImage(350, 50, BufferedImage.TYPE_INT_RGB);

        @Override
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            g.drawImage(bg, 0, 0, this);
        }
    };
    jsp.getViewport().setOpaque(false);
    gui.add(jsp);

    Main bih = new Main();
    JFrame f = new JFrame();
    f.add(gui);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.pack();
    f.setVisible(true);
}

From source file:Main.java

public static void main(String s[]) {
    JFrame frame = new JFrame("Slider Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(new Main());
    frame.pack();//from   w  w w  . j av a 2  s .co m
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    Main temp = new Main();
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(temp);//  www  .java  2 s . co m
    frame.pack();
    frame.setVisible(true);
    Thread updater = new Thread(temp.new CustomThread());
    updater.start();
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame("Composition");
    frame.add(new Main());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(400, 120);/*w  w  w  .  ja  v  a 2 s .c om*/
    frame.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 ww  .ja  v  a 2s  .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);
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    JFrame jf = new JFrame("Demo");
    Container cp = jf.getContentPane();
    MyCanvas tl = new MyCanvas();
    cp.add(tl);//from   www. j a va  2s . c  o  m
    jf.setSize(300, 200);
    jf.setVisible(true);
}

From source file:PrintLineByLine.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.add(new PrintLineByLine());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(420, 250);//ww w  .  j  a v a  2 s.co  m
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] a) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.add(new JScrollPaneDemo());
    f.setSize(500, 500);/*www.  j a  v a2 s.  c  o m*/
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    int MAX_CELLS = 30;

    DefaultListModel<String> listModel = new DefaultListModel<>();
    JList<String> myList = new JList<>(listModel);
    myList.setVisibleRowCount(8);//from w w w.jav a2  s. c  om

    for (int i = 0; i < MAX_CELLS; i++) {
        listModel.addElement("label " + i);
    }

    JTabbedPane jTabbedPane = new JTabbedPane();

    jTabbedPane.add("Test", new JScrollPane(myList));

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

From source file:MyButton.java

public static void main(String[] args) {
    MyButton close = new MyButton("Close");
    JFrame f = new JFrame();
    f.add(close);//from w w  w . ja v a  2s. co  m

    f.setSize(300, 200);
    f.setLocationRelativeTo(null);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
}