예제 #1
1
 public int getTitleHeight(Component c) {
   int th = 21;
   int fh = getBorderInsets(c).top + getBorderInsets(c).bottom;
   if (c instanceof JDialog) {
     JDialog dialog = (JDialog) c;
     th = dialog.getSize().height - dialog.getContentPane().getSize().height - fh - 1;
     if (dialog.getJMenuBar() != null) {
       th -= dialog.getJMenuBar().getSize().height;
     }
   } else if (c instanceof JInternalFrame) {
     JInternalFrame frame = (JInternalFrame) c;
     th = frame.getSize().height - frame.getRootPane().getSize().height - fh - 1;
     if (frame.getJMenuBar() != null) {
       th -= frame.getJMenuBar().getSize().height;
     }
   } else if (c instanceof JRootPane) {
     JRootPane jp = (JRootPane) c;
     if (jp.getParent() instanceof JFrame) {
       JFrame frame = (JFrame) c.getParent();
       th = frame.getSize().height - frame.getContentPane().getSize().height - fh - 1;
       if (frame.getJMenuBar() != null) {
         th -= frame.getJMenuBar().getSize().height;
       }
     } else if (jp.getParent() instanceof JDialog) {
       JDialog dialog = (JDialog) c.getParent();
       th = dialog.getSize().height - dialog.getContentPane().getSize().height - fh - 1;
       if (dialog.getJMenuBar() != null) {
         th -= dialog.getJMenuBar().getSize().height;
       }
     }
   }
   return th;
 }
예제 #2
0
  public static void main(String[] args) {
    Toolkit theKit = aWindow.getToolkit(); // Get the window Toolkit
    Dimension wndSize = theKit.getScreenSize(); // Get the screen size

    // Set the position to screen center & size to half screen size
    aWindow.setBounds(
        wndSize.width / 4,
        wndSize.height / 4, // Position
        wndSize.width / 2,
        wndSize.height / 2); // Size
    aWindow.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

    GridLayout grid = new GridLayout(5, 2, 30, 20); // Create a layout manager
    Container content = aWindow.getContentPane();
    content.setLayout(grid);

    EtchedBorder edge = new EtchedBorder(EtchedBorder.RAISED); // Button border

    // Now add ten Button compenents
    JButton button;
    for (int i = 1; i <= 10; i++) {
      content.add(button = new JButton("Press " + i));
      button.setBorder(edge);
    }

    aWindow.getContentPane().setBackground(new Color(238, 233, 233));
    aWindow.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);
  }
  /** 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);
  }
 /** Method to create and initialize the picture frame */
 private void createAndInitPictureFrame() {
   pictureFrame = new JFrame(); // create the JFrame
   pictureFrame.setResizable(true); // allow the user to resize it
   pictureFrame.getContentPane().setLayout(new BorderLayout()); // use border layout
   pictureFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); // when close stop
   pictureFrame.setTitle(picture.getTitle());
   PictureExplorerFocusTraversalPolicy newPolicy = new PictureExplorerFocusTraversalPolicy();
   pictureFrame.setFocusTraversalPolicy(newPolicy);
 }
  /** Create and initialize the scrolling image */
  private void createAndInitScrollingImage() {
    scrollPane = new JScrollPane();

    BufferedImage bimg = picture.getBufferedImage();
    imageDisplay = new ImageDisplay(bimg);
    imageDisplay.addMouseMotionListener(this);
    imageDisplay.addMouseListener(this);
    imageDisplay.setToolTipText("Click a mouse button on a pixel to see the pixel information");
    scrollPane.setViewportView(imageDisplay);
    pictureFrame.getContentPane().add(scrollPane, BorderLayout.CENTER);
  }
예제 #7
0
  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();
  }
예제 #8
0
  public static void main(String[] args) {
    try {
      UIManager.setLookAndFeel(TestManager.getLookAndFeelClassName());
    } catch (Exception e) {

    }

    JFrame f = new JFrame("Inbox (1 message)");
    f.getContentPane().add(new SplitPaneTest2());
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setSize(600, 400);
    f.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);
  }
예제 #10
0
 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);
 }
예제 #11
0
  public static void main(String arg[]) {

    JFrame f = new JFrame("SimpleBorder");
    Container content = f.getContentPane();
    JButton b = new JButton();
    b.setBorder(BorderFactory.createLineBorder(Color.blue, 10));
    content.add(b);
    f.setSize(200, 150);
    f.show();

    f.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        });
  }
예제 #12
0
  /**
   * 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();
 }
  /** Creates the North JPanel with all the pixel location and color information */
  private void createInfoPanel() {
    // create the info panel and set the layout
    JPanel infoPanel = new JPanel();
    infoPanel.setLayout(new BorderLayout());

    // create the font
    Font largerFont = new Font(infoPanel.getFont().getName(), infoPanel.getFont().getStyle(), 14);

    // create the pixel location panel
    JPanel locationPanel = createLocationPanel(largerFont);

    // create the color information panel
    JPanel colorInfoPanel = createColorInfoPanel(largerFont);

    // add the panels to the info panel
    infoPanel.add(BorderLayout.NORTH, locationPanel);
    infoPanel.add(BorderLayout.SOUTH, colorInfoPanel);

    // add the info panel
    pictureFrame.getContentPane().add(BorderLayout.NORTH, infoPanel);
  }
예제 #15
0
  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);
  }
예제 #16
0
  /** 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();
  }