public static void main(String[] args) throws IllegalArgumentException, IllegalAccessException { JFrame jf = new JFrame(); AttributesPanel colpal = new AttributesPanel(); colpal.setEntity(new FrameFact("hola")); colpal.setEntity(new FrameFact("hola")); jf.getContentPane().add(colpal); jf.pack(); jf.show(); jf.pack(); }
private void _displayRespStrInFrame() { final JFrame frame = new JFrame("Google Static Map - Error"); GUIUtils.setAppIcon(frame, "69.png"); // frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE); JTextArea response = new JTextArea(_respStr, 25, 80); response.addMouseListener( new MouseListener() { public void mouseClicked(MouseEvent e) {} public void mousePressed(MouseEvent e) { /*frame.dispose();*/ } public void mouseReleased(MouseEvent e) {} public void mouseEntered(MouseEvent e) {} public void mouseExited(MouseEvent e) {} }); frame.setContentPane(new JScrollPane(response)); frame.pack(); GUIUtils.centerOnScreen(frame); frame.setVisible(true); }
/** Simple test program. */ public static void main(String[] args) { final JFrame frame = new JFrame("Testing AddPersonDialog"); JButton button = new JButton("Click me"); button.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { FamilyTree tree = new FamilyTree(); AddPersonDialog dialog = new AddPersonDialog(frame, tree); dialog.pack(); dialog.setLocationRelativeTo(frame); dialog.setVisible(true); Person newPerson = dialog.getPerson(); if (newPerson != null) { tree.addPerson(newPerson); PrettyPrinter pretty = new PrettyPrinter(new PrintWriter(System.out, true)); pretty.dump(tree); } } }); frame.getContentPane().add(button); frame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(1); } }); frame.pack(); frame.setVisible(true); }
public static void main(String[] args) { final JPopupMenu menu = new JPopupMenu(); menu.setLayout(new GridLayout(0, 3, 5, 5)); final MenuedButton button = new MenuedButton("Icons", menu); for (int i = 0; i < 9; i++) { // replace "print.gif" with your own image final JLabel label = new JLabel("" + i); // new ImageIcon("resources/images/print.gif") ); label.addMouseListener( new MouseAdapter() { public void mouseClicked(MouseEvent e) { button.getMainButton().setIcon(label.getIcon()); menu.setVisible(false); } }); menu.add(label); } JFrame frame = new JFrame("Button Test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(new JLabel("Click Arrow Button To Show Popup"), BorderLayout.NORTH); frame.getContentPane().add(button, BorderLayout.CENTER); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); }
/** * Create the GUI and show it. For thread safety, this method should be invoked from the * event-dispatching thread. */ private static void createAndShowGUI() { // Create and set up the window. JFrame frame = new JFrame("ComboBoxDemo2"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Create and set up the content pane. JComponent newContentPane = new ComboBoxDemo2(); newContentPane.setOpaque(true); // content panes must be opaque frame.setContentPane(newContentPane); // Display the window. frame.pack(); frame.setVisible(true); }
public static void main(String args[]) { // UIManager.put("PopupMenu.border", new BorderUIResource.EmptyBorderUIResource(4,0,4,0)); try { UIManager.setLookAndFeel(QuaquaManager.getLookAndFeelClassName()); // UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); } catch (Exception e) { e.printStackTrace(); } JFrame f = new JFrame("PopupMenuTest: " + UIManager.getLookAndFeel().getName()); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(new PopupMenuTest()); f.pack(); f.setVisible(true); }
public static void createAndShowGUI() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) { ex.printStackTrace(); } JFrame frame = new JFrame("@title@"); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.getContentPane().add(new MainPanel()); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); }
/** Creates the JFrame and sets everything up */ private void createWindow() { // create the picture frame and initialize it createAndInitPictureFrame(); // set up the menu bar setUpMenuBar(); // create the information panel createInfoPanel(); // creates the scrollpane for the picture createAndInitScrollingImage(); // show the picture in the frame at the size it needs to be pictureFrame.pack(); pictureFrame.setVisible(true); }
/** * Main method for testing * * @param args arguments */ public static void main(String[] args) { JFrame frame = new JFrame(); frame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); AnimationWidget widget = new AnimationWidget(frame); frame.getContentPane().add(widget.getContents()); frame.pack(); frame.setVisible(true); }
public static void main(String s[]) { if (s.length > 0) j2kfilename = s[0]; else j2kfilename = "girl"; System.out.println(j2kfilename); isApplet = false; JFrame f = new JFrame("ImageViewer"); f.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); JApplet applet = new ImageViewer(); f.getContentPane().add("Center", applet); applet.init(); f.pack(); f.setSize(new Dimension(550, 550)); f.show(); }
public SyntaxTest() { JFrame frame = new JFrame(); frame.setSize(300, 300); JEditorPane editor = new JEditorPane(); DefaultSyntaxKit.initKit(); editor.setContentType("text/banking"); frame.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.weightx = 1.0; c.weighty = 1.0; c.fill = GridBagConstraints.BOTH; frame.add(editor, c); frame.pack(); frame.setVisible(true); }
public static void main(String[] args) { // create a JFrame to hold everything JFrame frame = new JFrame("Borders"); // Create labels with borders. int center = SwingConstants.CENTER; JLabel labelOne = new JLabel("raised BevelBorder", center); labelOne.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); JLabel labelTwo = new JLabel("EtchedBorder", center); labelTwo.setBorder(BorderFactory.createEtchedBorder()); JLabel labelThree = new JLabel("MatteBorder", center); labelThree.setBorder(BorderFactory.createMatteBorder(10, 10, 10, 10, Color.pink)); JLabel labelFour = new JLabel("TitledBorder", center); Border etch = BorderFactory.createEtchedBorder(); labelFour.setBorder(BorderFactory.createTitledBorder(etch, "Title")); JLabel labelFive = new JLabel("TitledBorder", center); Border low = BorderFactory.createLoweredBevelBorder(); labelFive.setBorder( BorderFactory.createTitledBorder(low, "Title", TitledBorder.RIGHT, TitledBorder.BOTTOM)); JLabel labelSix = new JLabel("CompoundBorder", center); Border one = BorderFactory.createEtchedBorder(); Border two = BorderFactory.createMatteBorder(4, 4, 4, 4, Color.blue); labelSix.setBorder(BorderFactory.createCompoundBorder(one, two)); // add components to the content pane Container c = frame.getContentPane(); // unecessary in 1.5+ c.setLayout(new GridLayout(3, 2)); c.add(labelOne); c.add(labelTwo); c.add(labelThree); c.add(labelFour); c.add(labelFive); c.add(labelSix); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); }
public void init() { // 添加按钮 JPanel buttonPanel = new JPanel(); buttonPanel.add(okButton); mainPanel.setLayout(new GridLayout(0, 3)); mainWin.add(mainPanel, BorderLayout.CENTER); JFormattedTextField intField0 = new JFormattedTextField( new InternationalFormatter(NumberFormat.getIntegerInstance()) { protected DocumentFilter getDocumentFilter() { return new NumberFilter(); } }); intField0.setValue(100); addRow("只接受数字的文本框", intField0); JFormattedTextField intField1 = new JFormattedTextField(NumberFormat.getIntegerInstance()); intField1.setValue(new Integer(100)); // 添加输入校验器 intField1.setInputVerifier(new FormattedTextFieldVerifier()); addRow("带输入校验器的文本框", intField1); // 创建自定义格式器对象 IPAddressFormatter ipFormatter = new IPAddressFormatter(); ipFormatter.setOverwriteMode(false); // 以自定义格式器对象创建格式化文本框 JFormattedTextField ipField = new JFormattedTextField(ipFormatter); ipField.setValue(new byte[] {(byte) 192, (byte) 168, 4, 1}); addRow("IP地址格式", ipField); mainWin.add(buttonPanel, BorderLayout.SOUTH); mainWin.pack(); mainWin.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); mainWin.setVisible(true); }
public void init() { jf.setLayout(new GridLayout(2, 4)); // 使用静态工厂方法创建BevelBorder Border bb = BorderFactory.createBevelBorder( BevelBorder.RAISED, Color.RED, Color.GREEN, Color.BLUE, Color.GRAY); jf.add(getPanelWithBorder(bb, "BevelBorder")); // 使用静态工厂方法创建LineBorder Border lb = BorderFactory.createLineBorder(Color.ORANGE, 10); jf.add(getPanelWithBorder(lb, "LineBorder")); // 使用静态工厂方法创建EmptyBorder,EmptyBorder就是在组件四周留空 Border eb = BorderFactory.createEmptyBorder(20, 5, 10, 30); jf.add(getPanelWithBorder(eb, "EmptyBorder")); // 使用静态工厂方法创建EtchedBorder Border etb = BorderFactory.createEtchedBorder(EtchedBorder.RAISED, Color.RED, Color.GREEN); jf.add(getPanelWithBorder(etb, "EtchedBorder")); // 直接创建TitledBorder,TitledBorder边框就是为原有的边框增加标题 TitledBorder tb = new TitledBorder( lb, "测试标题", TitledBorder.LEFT, TitledBorder.BOTTOM, new Font("StSong", Font.BOLD, 18), Color.BLUE); jf.add(getPanelWithBorder(tb, "TitledBorder")); // 直接创建MatteBorder,MatteBorder边框是EmptyBorder的子类, // 它可以指定留空区域的颜色或背景,此处是指定颜色 MatteBorder mb = new MatteBorder(20, 5, 10, 30, Color.GREEN); jf.add(getPanelWithBorder(mb, "MatteBorder")); // 直接创建CompoundBorder,CompoundBorder边框将两个边框组合成新边框 CompoundBorder cb = new CompoundBorder(new LineBorder(Color.RED, 8), tb); jf.add(getPanelWithBorder(cb, "CompoundBorder")); jf.pack(); jf.setVisible(true); }
private void _displayImgInFrame() { final JFrame frame = new JFrame("Google Static Map"); GUIUtils.setAppIcon(frame, "71.png"); // frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE); JLabel imgLbl = new JLabel(new ImageIcon(_img)); imgLbl.setToolTipText( MessageFormat.format( "<html>Image downloaded from URI<br>size: w={0}, h={1}</html>", _img.getWidth(), _img.getHeight())); GUIUtils.centerOnScreen(frame); frame.setVisible(true); frame.setContentPane(imgLbl); frame.pack(); frame.setResizable(false); imgLbl.addMouseListener( new MouseListener() { public void mouseClicked(MouseEvent e) {} public void mousePressed(MouseEvent e) { System.out.println("Mouse Listener: Mouse Clicked!"); mapIsUp = 1; sentX = 0.00; clickX = e.getX(); // Latitude clickY = e.getY(); // Longitude if ((clickX < (_img.getWidth() / 2)) && (clickY < (_img.getHeight() / 2))) { // 1st quadrant positive values sentX = Double.parseDouble(ttfLati.getText()) + (((-1 * (_img.getWidth() / 2)) + clickX) * pixelX); // Add to latitude sentY = Double.parseDouble(ttfLongi.getText()) + (((_img.getHeight() / 2) - clickY) * pixelY); // Add to Longitude System.out.println("Top left"); } else if ((clickX > (_img.getWidth() / 2)) && (clickY > (_img.getHeight() / 2))) { // 2nd quadrant negative values sentX = Double.parseDouble(ttfLati.getText()) + (((-1 * (_img.getHeight() / 2)) + clickX) * pixelX); sentY = Double.parseDouble(ttfLongi.getText()) + (((_img.getHeight() / 2) - clickY) * pixelY); System.out.println("Bottom Right"); } else if ((clickX < (_img.getWidth() / 2)) && (clickY > (_img.getHeight() / 2))) { // 3rd quadrant 1 positive 1 negative sentX = Double.parseDouble(ttfLati.getText()) + (((-1 * (_img.getWidth() / 2)) + clickX) * pixelX); sentY = Double.parseDouble(ttfLongi.getText()) + (((_img.getHeight() / 2) - clickY) * pixelY); System.out.println("Bottom Left"); } else { // 3rd quadrant 1 positive 1 negative sentX = Double.parseDouble(ttfLati.getText()) + (((-1 * (_img.getHeight() / 2)) + clickX) * pixelX); sentY = Double.parseDouble(ttfLongi.getText()) + (((_img.getHeight() / 2) - clickY) * pixelY); System.out.println("Top Right"); } BigDecimal toCoordsX = new BigDecimal(sentX); BigDecimal toCoordsY = new BigDecimal(sentY); sentX = (toCoordsX.setScale(6, BigDecimal.ROUND_HALF_UP)) .doubleValue(); // allows values of up to 6 decimal places sentY = (toCoordsY.setScale(6, BigDecimal.ROUND_HALF_UP)).doubleValue(); getCoords = sentX + " " + sentY; ttfLati.setText(Double.toString(sentX)); ttfLongi.setText(Double.toString(sentY)); System.out.println("... saving Coordinates"); saveLocation( getCoords); // pass getCoords through saveLocation. this string is appended to the // savedLocations file. System.out.println("... savedCoordinates"); // Update the Locations ComboBox with new additions ttfSave.removeAllItems(); // re-populate the ComboBox System.out.println("removed items"); getSavedLocations(); // run through file to get all locations for (int i = 0; i < loc.size(); i++) ttfSave.addItem(loc.get(i)); System.out.println("update combobox"); mapIsUp = 0; frame.dispose(); // closes window startTaskAction(); // pops up a new window } public void saveLocation(String xy) { BufferedWriter f = null; // created a bufferedWriter object try { f = new BufferedWriter( new FileWriter( "savedLocations.txt", true)); // evaluated true if file has not been created yet f.write(xy); // append passed coordinates and append to file if exists f.newLine(); f.flush(); } catch (IOException ioe) { ioe.printStackTrace(); } finally { // close the file if (f != null) { try { f.close(); } catch (IOException e) { // any error, catch exception System.err.println("Error: " + e.getMessage()); } } } } public void mouseReleased(MouseEvent e) {} public void mouseEntered(MouseEvent e) {} public void mouseExited(MouseEvent e) {} }); }
/** Make the frame for the user interface. */ private void makeFrame() { frame = new JFrame(calc.getTitle()); JPanel contentPane = (JPanel) frame.getContentPane(); contentPane.setLayout(new BorderLayout(8, 8)); contentPane.setBorder(new EmptyBorder(20, 20, 20, 20)); display = new JTextField(); contentPane.add(display, BorderLayout.NORTH); JPanel buttonPanel = new JPanel(new GridLayout(5, 4)); addButton(buttonPanel, "7"); addButton(buttonPanel, "8"); addButton(buttonPanel, "9"); addButton(buttonPanel, "Cl"); // had to change this, so it works in hexadecimal mode addButton(buttonPanel, "4"); addButton(buttonPanel, "5"); addButton(buttonPanel, "6"); addButton(buttonPanel, "?"); addButton(buttonPanel, "1"); addButton(buttonPanel, "2"); addButton(buttonPanel, "3"); addButton(buttonPanel, "0"); addButton(buttonPanel, "+"); addButton(buttonPanel, "-"); // Exercise 1 division addButton(buttonPanel, "/"); // Exercise 1 multi addButton(buttonPanel, "*"); addButton(buttonPanel, "="); contentPane.add(buttonPanel, BorderLayout.CENTER); status = new JLabel(calc.getAuthor()); contentPane.add(status, BorderLayout.SOUTH); // hexa stuff JPanel hexContainer = new JPanel(new GridLayout(2, 1)); JCheckBox hexBox = new JCheckBox("Hexadecimal mode"); hexBox.addActionListener(this); hexContainer.add(hexBox); hexPanel = new JPanel(new GridLayout(2, 3)); addButton(hexPanel, "A"); addButton(hexPanel, "B"); addButton(hexPanel, "C"); addButton(hexPanel, "D"); addButton(hexPanel, "E"); addButton(hexPanel, "F"); hexContainer.add(hexPanel); hexPanel.setVisible(false); // hide it because we start in decimal mode contentPane.add(hexContainer, BorderLayout.EAST); frame.pack(); }
/** * Create a new, empty, not-visible TaxRef window. Really just activates the setup frame and setup * memory monitor components, then starts things off. */ public MainFrame() { setupMemoryMonitor(); // Set up the main frame. mainFrame = new JFrame(basicTitle); mainFrame.setJMenuBar(setupMenuBar()); mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Set up the JTable. table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setSelectionBackground(COLOR_SELECTION_BACKGROUND); table.setShowGrid(true); // Add a blank table model so that the component renders properly on // startup. table.setModel(blankDataModel); // Add a list selection listener so we can tell the matchInfoPanel // that a new name was selected. table .getSelectionModel() .addListSelectionListener( new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (currentCSV == null) return; int row = table.getSelectedRow(); int column = table.getSelectedColumn(); columnInfoPanel.columnChanged(column); Object o = table.getModel().getValueAt(row, column); if (Name.class.isAssignableFrom(o.getClass())) { matchInfoPanel.nameSelected(currentCSV.getRowIndex(), (Name) o, row, column); } else { matchInfoPanel.nameSelected(currentCSV.getRowIndex(), null, -1, -1); } } }); // Set up the left panel (table + matchInfoPanel) JPanel leftPanel = new JPanel(); matchInfoPanel = new MatchInformationPanel(this); leftPanel.setLayout(new BorderLayout()); leftPanel.add(matchInfoPanel, BorderLayout.SOUTH); leftPanel.add(new JScrollPane(table)); // Set up the right panel (columnInfoPanel) JPanel rightPanel = new JPanel(); columnInfoPanel = new ColumnInformationPanel(this); progressBar.setStringPainted(true); rightPanel.setLayout(new BorderLayout()); rightPanel.add(columnInfoPanel); rightPanel.add(progressBar, BorderLayout.SOUTH); // Set up a JSplitPane to split the panels up. JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, false, leftPanel, rightPanel); split.setResizeWeight(1); mainFrame.add(split); mainFrame.pack(); // Set up a drop target so we can pick up files mainFrame.setDropTarget( new DropTarget( mainFrame, new DropTargetAdapter() { @Override public void dragEnter(DropTargetDragEvent dtde) { // Accept any drags. dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE); } @Override public void dragOver(DropTargetDragEvent dtde) {} @Override public void dropActionChanged(DropTargetDragEvent dtde) {} @Override public void dragExit(DropTargetEvent dte) {} @Override public void drop(DropTargetDropEvent dtde) { // Accept a drop as long as its File List. if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); Transferable t = dtde.getTransferable(); try { java.util.List<File> files = (java.util.List<File>) t.getTransferData(DataFlavor.javaFileListFlavor); // If we're given multiple files, pick up only the last file and load that. File f = files.get(files.size() - 1); loadFile(f, DarwinCSV.FILE_CSV_DELIMITED); } catch (UnsupportedFlavorException ex) { dtde.dropComplete(false); } catch (IOException ex) { dtde.dropComplete(false); } } } })); }