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

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

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

JFrame.add介绍

暂无

代码示例

代码示例来源:origin: knowm/XChange

@Override
 public void run() {
  // Create and set up the window.
  JFrame frame = new JFrame("XChart");
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.add(chartPanel);
  // Display the window.
  frame.pack();
  frame.setVisible(true);
 }
});

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

JFrame aFrame = new JFrame();
aFrame.add(new JPanel() {{
 setSize(100,100);
 setLocation(50,50);
 setBackground(Color.red);
}});

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

JFrame frame = new JFrame ("Test");
JTextArea textArea = new JTextArea ("Test");

JScrollPane scroll = new JScrollPane (textArea, 
  JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

frame.add(scroll);
frame.setVisible (true);

代码示例来源:origin: knowm/XChart

@Override
 public void run() {
  // Create and set up the window.
  // Add content to the window.
  frame.add(ExampleChartTester.this);
  // Display the window.
  frame.pack();
  frame.setVisible(true);
 }
});

代码示例来源:origin: i2p/i2p.i2p

final JFrame frame = new JFrame();
frame.setSize(0, 0);
final JPopupMenu menu = getSwingMainMenu();
menu.setFocusable(true);
frame.add(menu);
TrayIcon ti = new TrayIcon(getTrayImage(), tooltip, null);
ti.addMouseListener(new MouseListener() {

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

public static void main(String[] args) {
  JFrame frame = new TestScrollPane();
  JPanel panel = new JPanel();
  JTable table = new JTable();

  panel.setLayout(new BorderLayout());
  panel.add(new JLabel("NORTH"), BorderLayout.NORTH);
  panel.add(new JLabel("SOUTH"), BorderLayout.SOUTH);

  JScrollPane sp = new JScrollPane(table);
  sp.setBorder(BorderFactory.createEmptyBorder());
  panel.add(sp, BorderLayout.CENTER);
  frame.add(panel);

  frame.setVisible(true);
}

代码示例来源:origin: 4thline/cling

public void toggleLogPanel() {
  if (!logPanelVisible) {
    getView().add(getLogPanel(), BorderLayout.CENTER);
    getLogController().getLogTableModel().setPaused(false);
    logPanelVisible = true;
  } else {
    getView().remove(getLogPanel());
    getLogController().getLogTableModel().setPaused(true);
    logPanelVisible = false;
  }
  getView().pack();
}

代码示例来源:origin: knowm/XChange

@Override
 public void run() {
  // Create and set up the window.
  JFrame frame = new JFrame("XChart");
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.add(chartPanel);
  // Display the window.
  frame.pack();
  frame.setVisible(true);
 }
});

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

public static void main(String[] args) throws Exception {
  JFrame frame = new JFrame("Test");

  ImageIcon loading = new ImageIcon("ajax-loader.gif");
  frame.add(new JLabel("loading... ", loading, JLabel.CENTER));

  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.setSize(400, 300);
  frame.setVisible(true);
}

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

JFrame frame = new JFrame();
frame.setLayout(new GridLayout());
JLabel label = new JLabel("<html>First line<br>Second line</html>");
frame.add(label);
frame.pack();
frame.setVisible(true);

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

private static void createAndShowGUI() {
  // Create and set up the window.
  JFrame frame = new JFrame("SpotBugs browser integration Test");
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  // Add content to the window.
  frame.add(new TestDesktopIntegration());
  // Display the window.
  frame.pack();
  frame.setLocationRelativeTo(null);
  frame.setVisible(true);
}

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

JFrame frame = new JFrame();
frame.setLayout(new BorderLayout());
frame.setSize(200, 200);

// create the status bar panel and shove it down the bottom of the frame
JPanel statusPanel = new JPanel();
statusPanel.setBorder(new BevelBorder(BevelBorder.LOWERED));
frame.add(statusPanel, BorderLayout.SOUTH);
statusPanel.setPreferredSize(new Dimension(frame.getWidth(), 16));
statusPanel.setLayout(new BoxLayout(statusPanel, BoxLayout.X_AXIS));
JLabel statusLabel = new JLabel("status");
statusLabel.setHorizontalAlignment(SwingConstants.LEFT);
statusPanel.add(statusLabel);

frame.setVisible(true);

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

public static void main(String[] args) {
  JFrame frame = new JFrame();
  frame.setLayout(new GridBagLayout());
  JPanel panel = new JPanel();
  panel.add(new JLabel("This is a label"));
  panel.setBorder(new LineBorder(Color.BLACK)); // make it easy to see
  frame.add(panel, new GridBagConstraints());
  frame.setSize(400, 400);
  frame.setLocationRelativeTo(null);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.setVisible(true);
}

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

public static void main ( String[] args )
{
  JPanel middlePanel = new JPanel ();
  middlePanel.setBorder ( new TitledBorder ( new EtchedBorder (), "Display Area" ) );

  // create the middle panel components

  JTextArea display = new JTextArea ( 16, 58 );
  display.setEditable ( false ); // set textArea non-editable
  JScrollPane scroll = new JScrollPane ( display );
  scroll.setVerticalScrollBarPolicy ( ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS );

  //Add Textarea in to middle panel
  middlePanel.add ( scroll );

  // My code
  JFrame frame = new JFrame ();
  frame.add ( middlePanel );
  frame.pack ();
  frame.setLocationRelativeTo ( null );
  frame.setVisible ( true );
}

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

public static void main(String args[]){
  JFrame f = new JFrame();
  f.setLayout(new BorderLayout());
  final JPanel p = new JPanel();
  p.add(new JLabel("A Panel"));
  f.add(p, BorderLayout.CENTER);

  //create a button which will hide the panel when clicked.
  JButton b = new JButton("HIDE");
  b.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e){
        p.setVisible(false);
    }
  });

  f.add(b,BorderLayout.SOUTH);
  f.pack();
  f.setVisible(true);
}

代码示例来源:origin: stanfordnlp/CoreNLP

private void displayTsurgeonHelp() {
 if(tsurgeonHelpFrame != null) {
  tsurgeonHelpFrame.setVisible(true);
 } else {
  tsurgeonHelpFrame = new JFrame("TSurgeon Help...");
  JEditorPane helpText = new JEditorPane();
  helpText.setContentType("text/html");
  // StringBuffer s = new StringBuffer();
  // s.append(htmlTsurgeonHelp);
  helpText.setText(htmlTsurgeonHelp);
  helpText.setEditable(false);
  JScrollPane scroller = new JScrollPane(helpText);
  helpText.setCaretPosition(0);
  scroller.setPreferredSize(new Dimension(500,500));
  tsurgeonHelpFrame.add(scroller);
  tsurgeonHelpFrame.pack();
  tsurgeonHelpFrame.setBackground(Color.WHITE);
  tsurgeonHelpFrame.setVisible(true);
 }
}

代码示例来源:origin: stanfordnlp/CoreNLP

private void displayHelp() {
 if (helpFrame != null) {
  helpFrame.setVisible(true);
 } else {
  helpFrame = new JFrame("Tregex Help...");
  //JPanel helpPanel = new JPanel();
  JEditorPane helpText = new JEditorPane();
  helpText.setContentType("text/html");
  // StringBuffer s = new StringBuffer();
  // s.append(htmlHelp);
  helpText.setText(htmlHelp);
  helpText.setEditable(false);
  //helpPanel.add(helpText);
  JScrollPane scroller = new JScrollPane(helpText);
  helpText.setCaretPosition(0);
  scroller.setPreferredSize(new Dimension(500,500));
  helpFrame.add(scroller);
  helpFrame.pack();
  helpFrame.setBackground(Color.WHITE);
  helpFrame.setVisible(true);
  //helpFrame.repaint();
 }
}

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

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

  // 1. create the pipes
  PipedInputStream inPipe = new PipedInputStream();
  PipedInputStream outPipe = new PipedInputStream();

  // 2. set the System.in and System.out streams
  System.setIn(inPipe);
  System.setOut(new PrintStream(new PipedOutputStream(outPipe), true));

  PrintWriter inWriter = new PrintWriter(new PipedOutputStream(inPipe), true);

  // 3. create the gui 
  JFrame frame = new JFrame("\"Console\"");
  frame.add(console(outPipe, inWriter));
  frame.setSize(400, 300);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.setVisible(true);

  // 4. write some output (to JTextArea)
  System.out.println("Hello World!");
  System.out.println("Test");
  System.out.println("Test");
  System.out.println("Test");

  // 5. get some input (from JTextArea)
  Scanner s = new Scanner(System.in);
  System.out.printf("got from input: \"%s\"%n", s.nextLine());
}

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

import java.awt.*;

public class TestComponent extends JPanel {

  private void drawString(Graphics g, String text, int x, int y) {
    for (String line : text.split("\n"))
      g.drawString(line, x, y += g.getFontMetrics().getHeight());
  }

  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    drawString(g, "hello\nworld", 20, 20);
    g.setFont(g.getFont().deriveFont(20f));
    drawString(g, "part1\npart2", 120, 120);
  }

  public static void main(String s[]) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.add(new TestComponent());
    f.setSize(220, 220);
    f.setVisible(true);
  }
}

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

public static void main(String[] args) {
  JFrame frame = new JFrame();
  frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  frame.setBounds(0, 0, 300, 400);
  frame.setLayout(null);
  final JTabbedPane tabbedPane = new JTabbedPane();
  tabbedPane.addTab("One", new JPanel());
  tabbedPane.addTab("Two", new JPanel());
  tabbedPane.addTab("Three", new JPanel());
  tabbedPane.addChangeListener(new ChangeListener() {
    public void stateChanged(ChangeEvent e) {
      System.out.println("Tab: " + tabbedPane.getSelectedIndex());
    }
  });
  tabbedPane.setBounds(0, 0, 300, 400);
  frame.add(tabbedPane);
  frame.setVisible(true);
}

相关文章

JFrame类方法