javax.swing.JFrame.addComponentListener()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(208)

本文整理了Java中javax.swing.JFrame.addComponentListener()方法的一些代码示例,展示了JFrame.addComponentListener()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JFrame.addComponentListener()方法的具体详情如下:
包路径:javax.swing.JFrame
类名称:JFrame
方法名:addComponentListener

JFrame.addComponentListener介绍

暂无

代码示例

代码示例来源:origin: pmd/pmd

private void createRuleXML() {
  CreateXMLRulePanel rulePanel = new CreateXMLRulePanel(xpathQueryArea, codeEditorPane);
  JFrame xmlframe = new JFrame("Create XML Rule");
  xmlframe.setContentPane(rulePanel);
  xmlframe.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
  xmlframe.setSize(new Dimension(600, 700));
  xmlframe.addComponentListener(new java.awt.event.ComponentAdapter() {
    @Override
    public void componentResized(ComponentEvent e) {
      JFrame tmp = (JFrame) e.getSource();
      if (tmp.getWidth() < 600 || tmp.getHeight() < 700) {
        tmp.setSize(600, 700);
      }
    }
  });
  int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
  int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;
  xmlframe.pack();
  xmlframe.setLocation((screenWidth - xmlframe.getWidth()) / 2, (screenHeight - xmlframe.getHeight()) / 2);
  xmlframe.setVisible(true);
}

代码示例来源:origin: org.cytoscape/swing-application-impl

/**
   * Add a component listener to the app frame to get windows resize events.
   */
  private void addComponentListener() {
    frame.addComponentListener(new ComponentAdapter() {
        /**
         * Frame is resized.
         *
         * @param e Component Event.
         */
        public void componentResized(ComponentEvent e) {
          dividerLocation = -1;
        }
      });
  }
}

代码示例来源:origin: cytoscape/application

/**
   * Add a component listener to the app frame to get windows resize events.
   */
  private void addComponentListener() {
    frame.addComponentListener(new ComponentAdapter() {
        /**
         * Frame is resized.
         *
         * @param e Component Event.
         */
        public void componentResized(ComponentEvent e) {
          dividerLocation = -1;
        }
      });
  }
}

代码示例来源:origin: stackoverflow.com

JFrame jf = new JFrame();
jf.addComponentListener(new ComponentListener() {...});

代码示例来源:origin: klamonte/jexer

/**
 * Adds the specified component listener to receive component events from
 * this component. If listener l is null, no exception is thrown and no
 * action is performed.
 *
 * @param l the component listener
 */
public void addComponentListener(ComponentListener l) {
  if (frame != null) {
    frame.addComponentListener(l);
  } else {
    component.addComponentListener(l);
  }
}

代码示例来源:origin: au.gov.amsa.risky/geo-analyzer

@Override
  public void run() {
    final JFrame f = new JFrame("Vessel Traffic Density");
    // Sets the behavior for when the window is closed
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    // Add a layout manager so that the button is not placed on top
    // of the
    // label
    f.setLayout(new FlowLayout());
    // // Add a label and a button
    // f.add(new JLabel("Hello, world!"));
    // f.add(new JButton("Press me!"));
    f.add(DisplayPanel.this);
    // Arrange the components inside the window
    f.pack();
    // By default, the window is not visible. Make it visible.
    f.setVisible(true);
    f.addComponentListener(new java.awt.event.ComponentAdapter() {
      @Override
      public void componentResized(ComponentEvent e) {
        DisplayPanel.this.setPreferredSize(new Dimension(f
            .getWidth(), f.getHeight()));
      }
    });
  }
});

代码示例来源:origin: net.sourceforge.pmd/pmd-core

private void createRuleXML() {
  CreateXMLRulePanel rulePanel = new CreateXMLRulePanel(xpathQueryArea, codeEditorPane);
  JFrame xmlframe = new JFrame("Create XML Rule");
  xmlframe.setContentPane(rulePanel);
  xmlframe.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
  xmlframe.setSize(new Dimension(600, 700));
  xmlframe.addComponentListener(new java.awt.event.ComponentAdapter() {
    @Override
    public void componentResized(ComponentEvent e) {
      JFrame tmp = (JFrame) e.getSource();
      if (tmp.getWidth() < 600 || tmp.getHeight() < 700) {
        tmp.setSize(600, 700);
      }
    }
  });
  int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
  int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;
  xmlframe.pack();
  xmlframe.setLocation((screenWidth - xmlframe.getWidth()) / 2, (screenHeight - xmlframe.getHeight()) / 2);
  xmlframe.setVisible(true);
}

代码示例来源:origin: stackoverflow.com

frame.setVisible(true);
frame.addComponentListener(new ComponentListener(){

代码示例来源:origin: gurkenlabs/litiengine

private void initializeEventListeners() {
 this.getRenderComponent().addComponentListener(new ComponentAdapter() {
  @Override
  public void componentResized(final ComponentEvent evt) {
   resolution = getRenderComponent().getSize();
   resolutionChangedConsumer.forEach(consumer -> consumer.accept(GameWindow.this.getSize()));
  }
 });
 this.hostControl.addComponentListener(new ComponentAdapter() {
  @Override
  public void componentMoved(final ComponentEvent evt) {
   screenLocation = null;
  }
 });
}

代码示例来源:origin: sc.fiji/Interactive_3D_Surface_Plot

frame.addComponentListener(new ComponentAdapter(){

代码示例来源:origin: graphstream/gs-core

public void openInAFrame(boolean on) {
  if (on) {
    if (frame == null) {
      frame = new JFrame("GraphStream");
      frame.setLayout(new BorderLayout());
      frame.add(this, BorderLayout.CENTER);
      frame.setSize(800, 600);
      frame.setLocationRelativeTo(null);
      frame.setVisible(true);
      frame.addWindowListener(this);
      frame.addComponentListener(this);
      frame.addKeyListener(shortcuts);
    } else {
      frame.setVisible(true);
    }
  } else {
    if (frame != null) {
      frame.removeComponentListener(this);
      frame.removeWindowListener(this);
      frame.removeKeyListener(shortcuts);
      frame.remove(this);
      frame.setVisible(false);
      frame.dispose();
    }
  }
}

代码示例来源:origin: Pragmatists/tdd-trainings

public static void main(String[] args) {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("real-services.xml");
    
    final SwingMovieList swingMovieList = new SwingMovieList();
    MovieListPresenter movieListPresenter = new MovieListPresenter(
        swingMovieList, context.getBean(MovieRepository.class));
    swingMovieList.observeWith(movieListPresenter);

    JFrame frame = new MainApplicationFrame(swingMovieList);
    frame.addComponentListener ( new ComponentAdapter () {
      
      @Override
      public void componentShown ( ComponentEvent e ) {
        swingMovieList.shown();
      }
    });
    frame.setVisible(true);
  }
}

代码示例来源:origin: org.graphstream/gs-core

public void openInAFrame(boolean on) {
  if (on) {
    if (frame == null) {
      frame = new JFrame("GraphStream");
      frame.setLayout(new BorderLayout());
      frame.add(this, BorderLayout.CENTER);
      frame.setSize(800, 600);
      frame.setLocationRelativeTo(null);
      frame.setVisible(true);
      frame.addWindowListener(this);
      frame.addComponentListener(this);
      frame.addKeyListener(shortcuts);
    } else {
      frame.setVisible(true);
    }
  } else {
    if (frame != null) {
      frame.removeComponentListener(this);
      frame.removeWindowListener(this);
      frame.removeKeyListener(shortcuts);
      frame.remove(this);
      frame.setVisible(false);
      frame.dispose();
    }
  }
}

代码示例来源:origin: bcdev/beam

public JFrame getFrame() {
  if (mainFrame == null) {
    mainFrame = new JFrame("Product Grabber");
    mainFrame.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
    initUI();
    mainFrame.addComponentListener(new ComponentAdapter() {
      @Override
      public void componentHidden(final ComponentEvent e) {
        repositoryManager.stopUpdateRepository();
      }
    });
    mainFrame.add(mainPanel);
    mainFrame.setBounds(pgConfig.getWindowBounds());
    applyConfig(pgConfig);
    mainFrame.addComponentListener(new ComponentAdapter() {
      @Override
      public void componentMoved(final ComponentEvent e) {
        pgConfig.setWindowBounds(e.getComponent().getBounds());
      }
      @Override
      public void componentResized(final ComponentEvent e) {
        pgConfig.setWindowBounds(e.getComponent().getBounds());
      }
    });
    setUIComponentsEnabled(repositoryList.getItemCount() > 0);
  }
  return mainFrame;
}

代码示例来源:origin: brackeen/Scared

protected void initFrame(int width, int height) {
  // Create frame
  frame = new JFrame(appName);
  frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  frame.setIconImage(iconImage);
  enableOSXFullscreen(frame);
  // Add applet to contentPane
  setSize(width, height);
  final Container contentPane = frame.getContentPane();
  contentPane.setBackground(Color.BLACK);
  contentPane.setPreferredSize(new Dimension(width, height));
  contentPane.setLayout(null);
  contentPane.add(this);
  // Show frame
  frame.pack();
  Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
  frame.setLocation(Math.max(0, (dim.width - frame.getWidth()) / 2),
      Math.max(0, (dim.height - frame.getHeight()) / 2));
  frame.setVisible(true);
  // Start
  init();
  start();
  // Resize applet on frame resize
  frame.addComponentListener(new ComponentAdapter() {
    @Override
    public void componentResized(ComponentEvent e) {
      setBounds(contentPane.getBounds());
    }
  });
}

代码示例来源:origin: stackoverflow.com

public class FTW {
  public static void main(String[] args) throws IOException {

    JFrame myFrame = new JFrame("myJfTitle");
    myFrame.setSize(300,100);
    myFrame.setLayout(new BorderLayout());
    JPanel myPanel = new JPanel();
    JButton myButton = new JButton("Click me");
    JProgressBar myBar = new JProgressBar();
    myBar.setPreferredSize(new Dimension(myFrame.getWidth(),myFrame.getHeight())); //sets the size for the first time
    myFrame.addComponentListener(new ComponentAdapter()  //sets the size everytime the frame is resized
    {  
        public void componentResized(ComponentEvent evt) {
          Component c = (Component)evt.getSource();
          myBar.setPreferredSize(new Dimension(myFrame.getWidth(),myFrame.getHeight()));
        }
    });
    JPanel glass = (JPanel) myFrame.getGlassPane();
    glass.setVisible(true);
    myBar.setValue(50);
    glass.add(myButton, BorderLayout.CENTER);
    myPanel.add(myBar);
    myFrame.add(myPanel);
    myFrame.revalidate();
    myFrame.repaint();
    myFrame.setVisible(true);
}
}

代码示例来源:origin: GoldenGnu/jeveassets

jFrame.setIconImages(icons);
jFrame.addWindowListener(listener);
jFrame.addComponentListener(listener);
jFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

代码示例来源:origin: gephi/gephi-toolkit-demos

frame.addComponentListener(new ComponentAdapter() {
  @Override
  public void componentShown(ComponentEvent e) {

代码示例来源:origin: de.sciss/scisslib

final ComponentBoundsRestrictor	cbr = new ComponentBoundsRestrictor();
f.getContentPane().add( lb );
f.addComponentListener( new ComponentAdapter() {
  private void update()

代码示例来源:origin: org.orbisgis/orbisgis-view

/**
 * The user click on the Job label The JobList component must be shown
 * and the focus set on it
 */
public void onUserClickJobLabel() {
    closeJobPopup();
    jobPopup = new JFrame();
    jobPopup.setUndecorated(true);
    jobPopup.requestFocusInWindow();
    //Create the jobList Panel
    JobListPanel jobList = new JobListPanel();
    jobList.setRenderer(new JobListCellRenderer());
    jobList.setModel(runningJobs);
    jobList.setBorder(BorderFactory.createEtchedBorder());
    jobPopup.setContentPane(jobList);
    //On lost focus this window must be closed
    jobPopup.addFocusListener(
        EventHandler.create(FocusListener.class, this,
        "onJobPopupLostFocus", null, "focusLost"));
    //On resize , this window must be moved
    jobPopup.addComponentListener(
        EventHandler.create(ComponentListener.class,
        this, "onJobPopupResize", null, "componentResized"));
    //Do size and place
    jobPopup.setVisible(true);
    jobPopup.pack();
    onJobPopupResize();
}

相关文章

JFrame类方法