List of usage examples for javax.swing JFrame pack
@SuppressWarnings("deprecation") public void pack()
From source file:MainClass.java
public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container c = f.getContentPane(); c.add(new Justify()); f.pack(); f.setVisible(true);/* w ww . java 2s. c o m*/ }
From source file:de.longri.cachebox3.DesktopLauncher.java
public static void main(String[] args) { System.setProperty("org.lwjgl.util.NoChecks", "false"); CommandLine cmd = getCommandLine(args); //initialize platform bitmap factory AwtGraphics.init();//from w w w . jav a 2 s .c o m //initialize platform connector PlatformConnector.init(new DesktopPlatformConnector()); LwjglApplicationConfiguration config = new LwjglApplicationConfiguration(); config.resizable = false; config.useHDPI = true; config.samples = 10; config.width = 223; config.height = 397; config.title = "Cachebox 3.0"; config.stencil = 8; config.foregroundFPS = 30; config.backgroundFPS = 10; if (cmd.hasOption("note")) { //force note 4 layout config.width = 323; config.height = 574; } if (cmd.hasOption("scale")) { String value = cmd.getOptionValue("scale"); float scale = Float.parseFloat(value); CB.setGlobalScale(scale); config.width *= scale; config.height *= scale; } if (cmd.hasOption("gps")) { JFrame f; try { f = SimulatorMain.createFrame(); f.pack(); f.setResizable(false); f.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } initVtm(); // Don't change this LogLevel // Cachebox use the slf4j implematation for LibGdx as Log engine. // so set LogLevel on CB.class if you wont (USED_LOG_LEVEL) new LwjglApplication(new CacheboxMain(), config).setLogLevel(LwjglApplication.LOG_DEBUG); }
From source file:graphs.Graphs.java
public static void main(String[] args) { Graphs graph = new Graphs(); Graph<String, Integer> graph1 = new SparseGraph<String, Integer>(); graph1.addEdge(1, "A", "C"); graph1.addEdge(6, "A", "F"); graph1.addEdge(5, "B", "C"); graph1.addEdge(10, "B", "Z"); graph1.addEdge(3, "B", "D"); graph1.addEdge(4, "D", "E"); System.out.println("Original: vertices and edges"); System.out.println(graph1);/* w w w . j a va 2s.c o m*/ String path = BreadthSearch(graph1); System.out.println("print breadth first search path"); System.out.println(path); Layout<String, Integer> layout = new CircleLayout<String, Integer>(graph1); BasicVisualizationServer<String, Integer> vv = new BasicVisualizationServer<String, Integer>(layout); vv.setPreferredSize(new Dimension(600, 600)); //Sets the viewing area size vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller()); vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller()); JFrame frame = new JFrame("Simple Graph View"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(vv); frame.pack(); frame.setVisible(true); }
From source file:IntroExample.java
public static void main(String s[]) { JFrame frame = new JFrame("Simple Menu Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setJMenuBar(new IntroExample()); frame.pack(); frame.setVisible(true);//from www. j ava 2 s .c o m }
From source file:Main.java
public static void main(String args[]) { JFrame f = new JFrame("Label Demo"); f.setLayout(new FlowLayout()); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label = new JLabel("java2s.com"); label.setEnabled(false);//from w ww . j av a 2 s . com f.add(label); f.pack(); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { int ROW_HEIGHT = 40; String[] TABLE_COLUMNS = { "Foo", "Bar" }; DefaultTableModel tableModel = new DefaultTableModel(TABLE_COLUMNS, 2); JTable table = new JTable(tableModel); table.setRowHeight(ROW_HEIGHT);// w w w . java 2 s.c o m JScrollPane scrollpane = new JScrollPane(table); JButton addRowBtn = new JButton(new AbstractAction("Add Row") { @Override public void actionPerformed(ActionEvent arg0) { tableModel.addRow(new String[] { "", "" }); } }); JPanel btnPanel = new JPanel(); btnPanel.add(addRowBtn); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(scrollpane, BorderLayout.CENTER); f.getContentPane().add(btnPanel, BorderLayout.PAGE_END); f.pack(); f.setLocationByPlatform(true); f.setVisible(true); }
From source file:ColorDrag.java
public static void main(String args[]) { // Create two JLabel objects final JLabel label1 = new JLabel("Drag here"); JLabel label2 = new JLabel("Drop here"); // Register TransferHandler objects on them: label1 transfers its // foreground color and label2 transfers its background color. label1.setTransferHandler(new TransferHandler("foreground")); label2.setTransferHandler(new TransferHandler("background")); // Give label1 a foreground color other than the default // Make label2 opaque so it displays its background color label1.setForeground(new Color(100, 100, 200)); label2.setOpaque(true);//from w w w . j av a 2 s . c om // Now look for drag gestures over label1. When one occurs, // tell the TransferHandler to begin a drag. // Exercise: modify this gesture recognition so that the drag doesn't // begin until the mouse has moved 4 pixels. This helps to keep // drags distinct from sloppy clicks. To do this, you'll need both // a MouseListener and a MouseMotionListener. label1.addMouseMotionListener(new MouseMotionAdapter() { public void mouseDragged(MouseEvent e) { TransferHandler handler = label1.getTransferHandler(); handler.exportAsDrag(label1, e, TransferHandler.COPY); } }); // Create a window, add the labels, and make it all visible. JFrame f = new JFrame("ColorDrag"); f.getContentPane().setLayout(new FlowLayout()); f.getContentPane().add(label1); f.getContentPane().add(label2); f.pack(); f.setVisible(true); }
From source file:DnDDemo3.java
public static void main(String[] args) { JPanel north = new JPanel(); north.add(new JLabel("Drag from here:")); JTextField field = new JTextField(10); field.setDragEnabled(true);/* w ww. j ava 2 s . co m*/ north.add(field); final DefaultListModel listModel = new DefaultListModel(); listModel.addElement("first"); listModel.addElement("second"); final JList list = new JList(listModel); list.setDragEnabled(true); list.setTransferHandler(new TransferHandler() { public boolean canImport(TransferHandler.TransferSupport support) { if (!support.isDataFlavorSupported(DataFlavor.stringFlavor)) { return false; } JList.DropLocation dl = (JList.DropLocation) support.getDropLocation(); if (dl.getIndex() == -1) { return false; } else { return true; } } public boolean importData(TransferHandler.TransferSupport support) { if (!canImport(support)) { return false; } Transferable transferable = support.getTransferable(); String data; try { data = (String) transferable.getTransferData(DataFlavor.stringFlavor); } catch (Exception e) { return false; } JList.DropLocation dl = (JList.DropLocation) support.getDropLocation(); int index = dl.getIndex(); if (dl.isInsert()) { listModel.add(index, data); } else { listModel.set(index, data); } Rectangle r = list.getCellBounds(index, index); list.scrollRectToVisible(r); return true; } }); JScrollPane center = new JScrollPane(); center.setViewportView(list); list.setDropMode(DropMode.USE_SELECTION); JPanel cp = new JPanel(); cp.setLayout(new BorderLayout()); cp.add(north, BorderLayout.NORTH); cp.add(center, BorderLayout.CENTER); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setContentPane(cp); frame.pack(); frame.setVisible(true); }
From source file:ActionListenerTest2.java
public static void main(String[] args) { JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button = new JButton("Select File"); button.addActionListener(new MyActionListener()); frame.add(button);/*w ww. j a va 2 s . co m*/ frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws Exception { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JEditorPane jep = new JEditorPane(); jep.setText("Hello to the public"); frame.add(jep);//from w w w . j a v a 2 s . co m frame.pack(); frame.setVisible(true); highlight(jep, "public"); }