public javax.swing.JComponent[] parseMenuComponents(javax.swing.JMenuBar jMenuBar) {

    System.out.println("Start Parsing!!");

    javax.swing.JComponent menuComponents[] = (javax.swing.JComponent[]) jMenuBar.getComponents();

    return menuComponents;
  }
  private void rescaling() // method used to rescale UI
      {
    scalingfactor = Start.interfaceScalingFactor;

    // System.out.println("getPreferredSize().width=" + getPreferredSize().width);
    // System.out.println("getPreferredSize().height=" + getPreferredSize().height);

    int width = (int) (getPreferredSize().width * scalingfactor);
    int height = (int) (getPreferredSize().height * scalingfactor);
    // System.out.println("MainFrame scalingfactor=" + scalingfactor + " width=" + width + "
    // height=" + height);

    setPreferredSize(
        new Dimension(
            (int) (getPreferredSize().width * scalingfactor),
            (int) (getPreferredSize().height * scalingfactor)));
    setBounds(0, 0, (int) (1680 * scalingfactor), (int) (1050 * scalingfactor));
    for (Component comp : this.getComponents()) {
      comp.setPreferredSize(
          new Dimension(
              (int) (comp.getPreferredSize().width * scalingfactor),
              (int) (comp.getPreferredSize().height * scalingfactor)));
      comp.setBounds(
          (int) (comp.getX() * scalingfactor),
          (int) (comp.getY() * scalingfactor),
          (int) (comp.getWidth() * scalingfactor),
          (int) (comp.getHeight() * scalingfactor));

      // comp=rescaleComponent(comp);
      rescaleComponent(comp);

      if (comp instanceof JMenuBar) {
        JMenuBar jM = (JMenuBar) comp;
        for (Component lComp : jM.getComponents()) {
          rescaleComponent(lComp);
        }
      }
      if (comp instanceof JPanel) {
        JPanel jP = (JPanel) comp;
        for (Component lComp : jP.getComponents()) {
          rescaleComponent(lComp);
        }
      }
      if (comp instanceof JScrollPane) {
        JScrollPane jSp = (JScrollPane) comp;
        for (Component lComp : jSp.getComponents()) {
          rescaleComponent(lComp);
        }
      }
    }
    repaint();
    revalidate();
  }
Exemple #3
0
 public static void addFastKeys(JMenuBar menuBar) {
   for (Component menuComponent : menuBar.getComponents()) { // iterate over menus
     JMenu menu = (JMenu) menuComponent;
     menu.setMnemonic(menu.getText().charAt(menu.getText().indexOf('&') + 1));
     menu.setText(menu.getText().replace("&", ""));
     for (Component menuItemComponent : menu.getMenuComponents())
       if (menuItemComponent instanceof JMenuItem) { // skip separators
         JMenuItem menuItem = (JMenuItem) menuItemComponent;
         menuItem.setMnemonic(menuItem.getText().charAt(menuItem.getText().indexOf('&') + 1));
         menuItem.setText(menuItem.getText().replace("&", ""));
       }
     /*
     for (int count = 0; count < menu.getMenuComponentCount(); count++) {  //iterate over menu items
        Component menuItemComponent = menu.getMenuComponent(count);
        if (menuItemComponent instanceof JMenuItem) {   //skip separators
           JMenuItem menuItem = (JMenuItem)menuItemComponent;
           menuItem.setMnemonic(menuItem.getText().charAt(
                 menuItem.getText().indexOf('&') + 1));
           menuItem.setText(menuItem.getText().replace("&", ""));
           }
        }
     */
   }
 }