Java Code Examples for javax.swing.JFrame.setLayout()

The following are Jave code examples for showing how to use setLayout() of the javax.swing.JFrame class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: SpotSpotter   File: TextField.java   View Source Code Vote up 8 votes
public static void main(String[] args) {
	JTextFieldDemo1();
	final JFrame f = new JFrame("Welcome To Earth!");
	final JTextField name = new JTextField(30);
	final JTextField noed = new JTextField("HJW", 10);
	final JLabel nameLab = new JLabel("�����û�����:");
	final JLabel noedLab = new JLabel("���ɱ༭�ı� ");
	noed.setEnabled(false);
	name.setColumns(30);
	noed.setColumns(30);
	f.setLayout(new GridLayout(3, 2));// ���ò��ֹ�����
	f.add(nameLab);
	f.add(name);
	f.add(noedLab);
	f.add(noed);
	f.setSize(300, 100);
	f.setLocation(300, 200);
	f.setVisible(true);

}
 
Example 2
Project: call-IDE   File: ConsoleCore.java   View Source Code Vote up 6 votes
/**
 * Description: dispatches the console from its current place properly.
 */
public static void  dispatch(JScrollPane scrollPane, JTextPane cons,
                             JTabbedPane outputTabs, Component tabComp, JFrame frame,
                             Boolean consoleOut, Attachable mainFrame) {
    frame.setSize(600, 400);
    frame.setLocationRelativeTo( (Component) mainFrame);
    frame.setLayout(new BorderLayout());
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    
    scrollPane.setViewportView(cons);
    frame.add(scrollPane);
    
    if (frame.getWindowListeners().length > 0)
        frame.removeWindowListener(frame.getWindowListeners()[0]);
    frame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            mainFrame.attachConsole();
        }
    });
    frame.setVisible(true);
}
 
Example 3
Project: openjdk-jdk10   File: JComboBoxPopupLocation.java   View Source Code Vote up 6 votes
private static void setup(final Point tmp) {
    comboBox = new JComboBox<>();
    for (int i = 1; i < 7; i++) {
        comboBox.addItem("Long-long-long-long-long text in the item-" + i);
    }
    String property = System.getProperty(PROPERTY_NAME);
    comboBox.putClientProperty(PROPERTY_NAME, Boolean.valueOf(property));
    frame = new JFrame();
    frame.setAlwaysOnTop(true);
    frame.setLayout(new FlowLayout());
    frame.add(comboBox);
    frame.pack();
    frame.setSize(frame.getWidth(), SIZE);
    frame.setVisible(true);
    frame.setLocation(tmp.x, tmp.y);
}
 
Example 4
Project: jdk8u-jdk   File: bug7189299.java   View Source Code Vote up 6 votes
private static void setup() {
    /**
     * Note the input type is not restricted to "submit". Types "image",
     * "checkbox", "radio" have the same problem.
     */
    html = new JEditorPane("text/html",
            "<html><body><form action=\"http://localhost.cgi\">"
                    + "<input type=submit name=submit value=\"submit\"/>"
                    + "</form></body></html>");
    frame = new JFrame();
    frame.setLayout(new BorderLayout());
    frame.add(html, BorderLayout.CENTER);
    frame.setSize(200, 100);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
}
 
Example 5
Project: util4j   File: TestMethodReference.java   View Source Code Vote up 6 votes
public static void main(String[] args) {

        JFrame frame = new JFrame();
        frame.setLayout(new FlowLayout());
        frame.setVisible(true);
		
        JButton button1 = new JButton("点我!");
        JButton button2 = new JButton("也点我!");
		
        frame.getContentPane().add(button1);
        frame.getContentPane().add(button2);
        //这里addActionListener方法的参数是ActionListener,是一个函数式接口
        //使用lambda表达式方式
        button1.addActionListener(e -> { System.out.println("这里是Lambda实现方式"); });
        //使用方法引用方式
        button2.addActionListener(TestMethodReference::doSomething);
        
    }
 
Example 6
Project: batmapper   File: CorpseTest1.java   View Source Code Vote up 5 votes
public static void main( String[] args ) {

        JFrame frame = new JFrame( "" );
        frame.setLayout( new FlowLayout() );
        frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
        frame.getContentPane().add( new CorpsePanel( "", new MockPlugin() ) );
        frame.setSize( 1200, 800 );
//    	frame.pack();
        frame.setVisible( true );

    }
 
Example 7
Project: ALTTPMenuPractice   File: MenuPractice.java   View Source Code Vote up 5 votes
/**
 * Warning with instructions for failed library loading
 */
public static void showWarning() {
	// try to set LaF
	try {
		UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
	} catch (Exception e2) {
		// do nothing
	} //end System
	JFrame x = new JFrame();
	x.setLayout(new BorderLayout());
	x.setTitle("Libraries missing");
	x.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	x.add(new JLabel(
			String.join("",
					new String[] {
							"<html>",
							"<div style=\"padding: 13px; font-size: 10px;\">",
							"Your /lib directory not contain all necessary libraries to run JInput.",
							"<br /><br />",
							"To remedy this, download the latest release of MenuSimulator from",
							"<br />",
							"https://github.com/fatmanspanda/ALTTPMenuPractice/releases",
							"<br /><br />",
							"The application will halt when you close this window.",
							"</div>",
							"</html>"
			})),
			BorderLayout.NORTH);
	x.setMinimumSize(new Dimension(500,300));
	x.setLocation(200, 200);
	x.setVisible(true);
}
 
Example 8
Project: JAddOn   File: JExpandableTextArea.java   View Source Code Vote up 5 votes
public static void test() {
    JFrame frame = new JFrame();
    frame.setPreferredSize(new Dimension(400, 400));
    frame.setLayout(new BorderLayout());
    JExpandableTextArea eta = new JExpandableTextArea(10, 20);
    JScrollPane sp = new JScrollPane(eta);
    JPanel panel = new JPanel();
    panel.add(sp);
    frame.add(panel, BorderLayout.CENTER);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}
 
Example 9
Project: Install_Builder_Universal   File: LogWindow.java   View Source Code Vote up 5 votes
public LogWindow() {
	frame = new JFrame();
	frame.setTitle("Latest Log");
	frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
	frame.setSize(600, 480);
	frame.setLocationRelativeTo(null);
	frame.setResizable(false);
	frame.setLayout(null);
	
	panel = new JPanel();
	frame.add(panel);
	
	init();
}
 
Example 10
Project: jaer   File: OpenCVFlow.java   View Source Code Vote up 5 votes
public void displayImage(Image img2) {
    //BufferedImage img=ImageIO.read(new File("/HelloOpenCV/lena.png"));
    ImageIcon icon = new ImageIcon(img2);
    JFrame frame = new JFrame();
    frame.setLayout(new FlowLayout());
    frame.setSize(img2.getWidth(null) + 50, img2.getHeight(null) + 50);
    JLabel lbl = new JLabel();
    lbl.setIcon(icon);
    frame.add(lbl);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}
 
Example 11
Project: visuflow-plugin   File: GraphManager.java   View Source Code Vote up 5 votes
/**
 * Creates an instance of JFrame {@link #panel} and adds the graph view {@link #view} to the {@link #panel}.
 * @author Shashank B S
 */
private void createPanel() {
	JFrame temp = new JFrame();
	temp.setLayout(new BorderLayout());
	panel = temp.getContentPane();
	panel.add(headerBar,BorderLayout.PAGE_START);
	panel.add(view);
	panel.add(settingsBar, BorderLayout.PAGE_END);
}
 
Example 12
Project: batmapper   File: ManualTest1.java   View Source Code Vote up 5 votes
public static void main( String[] args ) {

        JFrame frame = new JFrame( "Simple Graph View" );
        frame.setLayout( new FlowLayout() );
        frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
        frame.getContentPane().add( new ManualPanel() );

        frame.pack();
        frame.setVisible( true );

    }
 
Example 13
Project: openjdk-jdk10   File: JMenuBarOverlapping.java   View Source Code Vote up 5 votes
protected void prepareControls() {
    frame = new JFrame("Mixing : Dropdown Overlapping test");
    frame.setLayout(new GridLayout(0,1));
    frame.setSize(200, 200);
    frame.setVisible(true);

    menuBar = new JMenuBar();
    JMenu menu = new JMenu("Test Menu");
    ActionListener menuListener = new ActionListener() {

        public void actionPerformed(ActionEvent event) {
            lwClicked = true;
        }
    };

    JMenuItem item;
    menu.add(item = new JMenuItem("first"));
    item.addActionListener(menuListener);
    separator = new JSeparator();
    separator.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            spClicked = true;
        }
    });
    menu.add(separator);

    for (int i = 0; i < petStrings.length; i++) {
        menu.add(item = new JMenuItem(petStrings[i]));
        item.addActionListener(menuListener);
    }
    menuBar.add(menu);
    frame.setJMenuBar(menuBar);

    propagateAWTControls(frame);
    frame.setVisible(true);
}
 
Example 14
Project: Tarski   File: Visualization.java   View Source Code Vote up 5 votes
public void showModel() {
  xmlCreator.setMetamodel(false);
  frame = new JFrame("Visualization");
  frame.setLayout(new BorderLayout());
  frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
  frame.add(getGraph(), BorderLayout.CENTER);
  frame.setVisible(true);
  frame.setSize(500, 500);
}
 
Example 15
Project: Install_Builder_Universal   File: AboutWindow.java   View Source Code Vote up 5 votes
public AboutWindow() {
	frame = new JFrame();
	frame.setTitle("About");
	frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
	frame.setSize(325, 280);
	frame.setLocationRelativeTo(null);
	frame.setResizable(false);
	frame.setLayout(null);
	
	panel = new JPanel();
	frame.add(panel);
	
	initialize();
	frame.setVisible(true);
}
 
Example 16
Project: incubator-netbeans   File: TestUtils.java   View Source Code Vote up 4 votes
public static void showDiff(CharSequence first, CharSequence second) throws IOException, InterruptedException {

        DiffProvider diffProvider = Lookup.getDefault().lookup(DiffProvider.class);

        if(diffProvider == null) {
           throw new IllegalStateException("No DiffProvider in lookup!"); 
        }

        Reader r1 = new StringReader(first.toString());
        Reader r2 = new StringReader(second.toString());
        StreamSource in = StreamSource.createSource("input", "input", "text/css", r1);
        StreamSource out = StreamSource.createSource("output", "output", "text/css", r2);

        DiffController dc = DiffController.createEnhanced(in, out);

        final JFrame jf = new JFrame("Diff");
        jf.setLayout(new BorderLayout());
        jf.add(BorderLayout.CENTER, dc.getJComponent());
        final Object lock = new Object();

        jf.addWindowListener(new WindowAdapter() {

            @Override
            public void windowClosing(WindowEvent we) {
                synchronized (lock) {
                    lock.notify();
                }
            }
        });
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                jf.setPreferredSize(new Dimension(800, 600));
                jf.pack();
                jf.setVisible(true);


            }
        });

        synchronized (lock) {
            lock.wait(10 * 60 * 1000); //timeout 10 mins
        }
    }
 
Example 17
Project: batmapper   File: MapperTest1.java   View Source Code Vote up 4 votes
public static void main( String[] args ) {
        SparseMultigraph<Room, Exit> graph = new SparseMultigraph<Room, Exit>();


        MapperEngine engine = new MapperEngine( graph );

        JFrame frame = new JFrame( "Simple Graph View" );
        frame.setLayout( new FlowLayout() );
        frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
        frame.getContentPane().add( engine.getPanel() );

        frame.pack();
        frame.setVisible( true );

        HashSet<String> exits = new HashSet<String>();
        exits.add( "ne" );
        exits.add( "n" );
        engine.moveToRoom( "testArea", "1", "enter path", false, "areaFirstRoom", "jshgfskgyfhsgfjhtsgdfhgsdfsygfsgdyfuysgdfjkhsgdfskuygfsuygfusygfuysd", exits );
        exits.clear();
        exits.add( "ne" );
        exits.add( "n" );
        exits.add( "w" );
        exits.add( "sw" );
        engine.moveToRoom( "testArea", "2", "n", false, "secondRoom", "jshgfskgyfhsgfjhtsgdfhgsdfsygfsgdyfuysgdfjkhsgdfskuygfsuygfusygfuysd", exits );
        exits.clear();
        exits.add( "ne" );
        exits.add( "n" );
        exits.add( "w" );
        exits.add( "sw" );
        engine.moveToRoom( "testArea", "3", "e", true, "thirdRoom", "jshgfskgyfhsgfjhtsgdfhgsdfsygfsgdyfuysgdfjkhsgdfskuygfsuygfusygfuysd", exits );
        exits.clear();
        exits.add( "ne" );
        exits.add( "n" );
        exits.add( "w" );
        exits.add( "sw" );
        engine.moveToRoom( "testArea", "4", "s", true, "fourthRoom", "jshgfskgyfhsgfjhtsgdfhgsdfsygfsgdyfuysgdfjkhsgdfskuygfsuygfusygfuysd", exits );
        exits.clear();
        exits.add( "w" );
        exits.add( "w" );
        exits.add( "e" );
        exits.add( "e" );
        engine.moveToRoom( "testArea", "5", "w", true, "fifthRoom", "jshgfskgyfhsgfjhtsgdfhgsdfsygfsgdyfuysgdfjkhsgdfskuygfsuygfusygfuysd", exits );
        exits.clear();
        exits.add( "ne" );
        exits.add( "nw" );
        exits.add( "sw" );
        exits.add( "se" );
        engine.moveToRoom( "testArea", "6", "n", false, "sixthRoom", "jshgfskgyfhsgfjhtsgdfhgsdfsygfsgdyfuysgdfjkhsgdfskuygfsuygfusygfuysd", exits );
        exits.clear();
        exits.add( "ne" );
        exits.add( "nw" );
        exits.add( "sw" );
        exits.add( "se" );
        engine.moveToRoom( "testArea", "7", "s", true, "seventhRoom", "jshgfskgyfhsgfjhtsgdfhgsdfsygfsgdyfuysgdfjkhsgdfskuygfsuygfusygfuysd", exits );
//    	exits.clear(); exits.add("ne"); exits.add("nw");exits.add("sw"); exits.add("se");
//    	engine.moveToRoom("testArea", "1", "jump to start", false, "areaFirstRoom", "jshgfskgyfhsgfjhtsgdfhgsdfsygfsgdyfuysgdfjkhsgdfskuygfsuygfusygfuysd", exits);

    }
 
Example 18
Project: GroupControlDroidClient   File: Entrance.java   View Source Code Vote up 4 votes
/**
 * 点击测试连接按钮
 * 
 * @param evt
 */
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
	// TODO add your handling code here:
	JFrame frame = new JFrame("设备连接测试");
	LayoutManager layout = new GridLayout(2, 2);
	frame.setLayout(layout);
	frame.setBounds(20, 20, 300, 100);
	frame.setVisible(true);
	frame.setResizable(false);
	frame.setLocationRelativeTo(null);

	TextField textFiled1 = new TextField("可用设备数");
	textFiled1.setEditable(false);
	connectedCountDeviceTextField.setEditable(false);
	frame.getContentPane().add(textFiled1);
	frame.getContentPane().add(connectedCountDeviceTextField);

	TextField textFiled2 = new TextField("总设备数");
	textFiled2.setEditable(false);
	totalCountDeviceTextField.setEnabled(false);
	frame.getContentPane().add(textFiled2);
	frame.getContentPane().add(totalCountDeviceTextField);

	// 设备数监听
	Thread countDeviceThread = new Thread(new Runnable() {
		@Override
		public void run() {
			int connected = 0, total = 0;// 已在线设备数,总设备数
			AndroidDebugBridge bridge = AdbUtil.getADBInstance();
			if (bridge != null) {
				try {
					while (!Thread.currentThread().isInterrupted()) {
						IDevice[] devices = bridge.getDevices();
						if (devices != null) {
							total = devices.length;
							connected = 0;
							for (IDevice device : devices) {
								if (device != null && device.isOnline()) {
									connected++;
								}
							}
						}
						connectedCountDeviceTextField.setText(String.format("%d", connected));
						totalCountDeviceTextField.setText(String.format("%d", total));

						Thread.sleep(500);

					}
				} catch (InterruptedException e) {
					logger.info("设备数目监听线程退出");
				}
			}
		}
	}, "CountDeviceThread");
	countDeviceThread.start();

	/* 窗口退出,退出线程 */
	frame.addWindowListener(new WindowAdapter() {
		public void windowClosing(WindowEvent we) {
			countDeviceThread.interrupt();
		}
	});
}
 
Example 19
Project: What-Happened-to-Station-7   File: Station7.java   View Source Code Vote up 4 votes
public static void main(String... args) throws Throwable
{
	JFrame window = new JFrame();
	window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	window.setTitle("What Happened to Station 7");
	window.setMinimumSize(new Dimension(400, 225));
	window.setLayout(new GridBagLayout());
	window.setExtendedState(JFrame.MAXIMIZED_BOTH);

	JFrame opening_text = new JFrame();
	opening_text.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
	opening_text.setTitle("This Is What Happened to Station 7");
	JTextArea textField = new JTextArea(
			"The date is 123.5432.1241511    Station 7 is in full operation when suddenly one of the arachnids spot a rather large blue and yellow battle-cruiser barreling towards the aft section of the outer wheel. It suddenly plunges it self deep within the station. The flag suddenly comes within view… Its the swedes on their eternal quest to increase their GDP. They start to scatter but they are not quick enough to survive the army of Carl XVI Gustaf. The Dramatic entrance of the battle-cruiser had created a hull breach and the amount of air in the station was starting to drop; those blast doors can only hold so long….																																																		You Play as the aliens represented by the Purple hexes your objective is to get to the next floor of Staition 7 via the cyan ecape doors the sweds represented by the blue tiles are out to get you it would be in your best intrests to avoid them as they will kill you very quickly, if you notics your color shifting it indicats a change in helth and you will be best adviced to seek out the red health boxes but be carful as they will only heal you so much");
	textField.setLineWrap(true);
	textField.setWrapStyleWord(true);
	opening_text.setMinimumSize(new Dimension(400, 225));
	opening_text.add(textField, BorderLayout.PAGE_START);
	opening_text.setExtendedState(JFrame.MAXIMIZED_BOTH);
	opening_text.setAlwaysOnTop(true);

	JFrame closing_text = new JFrame();
	closing_text.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	closing_text.setTitle("You Have Fell to the Swedes");
	JTextArea text = new JTextArea("You have failed to save your self…. The swedes trudge on obliterating the remaining inhabitants of the station. ");
	text.setLineWrap(true);
	text.setWrapStyleWord(true);
	closing_text.setMinimumSize(new Dimension(400, 225));
	closing_text.add(text, BorderLayout.PAGE_START);
	closing_text.setExtendedState(JFrame.MAXIMIZED_BOTH);

	SoundStuff soundStuff = new SoundStuff();
	soundStuff.dbol();

	Game game = new Game();

	GameRenderer render = new GameRenderer(game);
	render.addListeners(window);
	GridBagConstraints layoutGame = new GridBagConstraints();
	layoutGame.weightx = .9;
	layoutGame.weighty = .9;
	layoutGame.fill = GridBagConstraints.BOTH;
	layoutGame.anchor = GridBagConstraints.NORTH;
	window.add(render, layoutGame);

	GameInfo info = new GameInfo(game);
	info.addListeners();
	GridBagConstraints layoutInfo = new GridBagConstraints();
	layoutInfo.weightx = .1;
	layoutInfo.weighty = .1;
	layoutInfo.fill = GridBagConstraints.BOTH;
	layoutInfo.anchor = GridBagConstraints.NORTH;
	layoutInfo.gridy = 1;
	window.add(info, layoutInfo);

	game.init(render.new UIInterface(), info.new UIInterface());

	closing_text.setVisible(true);
	window.setVisible(true);
	opening_text.setVisible(true);
	Scanner reader = new Scanner(System.in);
	int n = reader.nextInt();
	if (n == 42)
	{
		System.out.print("adadfafd");
		SoundStuff cam = null;
		cam = new SoundStuff();
		cam.CCCP();
		reader.close();
	}
}
 
Example 20
Project: CarFender   File: CarFender.java   View Source Code Vote up 2 votes
public static void main(String[] args) {
	System.out.println("Hello, World!");
	
	
	
	things.add(new Thing("heart.png"));
	
	for(int i = 0; i < 12; i++) things.add(new Thing("healthBar/frame-" + i + ".png"));
	for(int i = 0; i < 1; i++) things.add(new Thing("wheel/frame-" + i + ".png"));
	things.add(new Thing("monsters/BokTop_Mon.png"));
	things.add(new Thing("monsters/LazTop_Mon.png"));
	things.add(new Thing("monsters/MudSid_Mon.png"));
	things.add(new Thing("monsters/MudTop_Mon.png"));
	things.add(new Thing("monsters/SarSid_Mon.png"));
	things.add(new Thing("monsters/SarTop_Mon.png"));
	things.add(new Thing("monsters/SekSid_Mon.png"));
	things.add(new Thing("monsters/SekTop_Mon.png"));
	things.add(new Thing("monsters/SikTop_Mon.png"));
	things.add(new Thing("monsters/TenGre_Mon.png"));
	things.add(new Thing("monsters/TenSid_Mon.png"));
	things.add(new Thing("monsters/Tib2Top_Mon.png"));
	things.add(new Thing("monsters/Tib3Top_Mon.png"));
	things.add(new Thing("monsters/TibTop_Mon.png"));
	
	things.add(new Thing("tree/TREE.png"));
	things.add(new Thing("tree/TREEDOS.png"));

	
	car = new Thing("car.png");
	
	displayFrame = new JFrame();	
	displayFrame.setLayout(new BorderLayout());
	
	
	gamePanel = new GameDisplay(car);	
	
	displayFrame.add(gamePanel);
	
	ThingsLogic logic = new ThingsLogic();
	
	Timer timer = new Timer();
	TimerTask myTask = new TimerTask() {
	    @Override
	    public void run() {
	    	logic.tick(things);
			gamePanel.updateThingsArraylist(things);
			gamePanel.repaint();
	    }
	};

	timer.schedule(myTask, 0, 1);
	
	
	
	displayFrame.pack();
	displayFrame.setVisible(true);
	
	
	
	
	
}