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

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

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

JFrame.setContentPane介绍

暂无

代码示例

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

public static void main(String[] args) {
  JFrame frame = new JFrame("MyForm");
  frame.setContentPane(new MyForm().mainPanel);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.pack();
  frame.setVisible(true);
}

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

JLabel javaHomeLabel = new JLabel("java.home=" + System.getProperty("java.home"));
setLayout(new BorderLayout());
add(versionLabel, BorderLayout.PAGE_START);
add(javaHomeLabel, BorderLayout.PAGE_END);
JFrame frame = new JFrame("MyJavaMacOSXApp");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
MyJavaMacOSXApp newContentPane = new MyJavaMacOSXApp();
newContentPane.setOpaque(true); 
frame.setContentPane(newContentPane);
frame.pack();
frame.setVisible(true);

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

JFrame frame = new JFrame("Colored Trails");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
JPanel firstPanel = new JPanel();
firstPanel.setLayout(new GridLayout(4, 4));
firstPanel.setMaximumSize(new Dimension(400, 400));
JPanel secondPanel = new JPanel();
secondPanel.setLayout(new GridLayout(5, 13));
secondPanel.setMaximumSize(new Dimension(520, 200));
frame.setContentPane(mainPanel);

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

JFrame frame = new JFrame(title);
frame.setContentPane(new JLabel(new ImageIcon(image)));
frame.pack();
frame.setVisible(true);

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

import javax.swing.JFrame;
import javax.swing.JLabel;

public class Window
{
  public static void main(String[] args)
  {
    JLabel lblLangeFrage = new JLabel(
        "<html><body><p> bl bl bl bl bl bl bl bl b lb lb lb lb lb lb b lb bl b</p> </body> </html>");
    JFrame fenster = new JFrame();
    fenster.setContentPane(lblLangeFrage);
    fenster.setVisible(true);
    fenster.setSize(130, 130);
}
}

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

final JFrame frame = new JFrame("Nested Layout Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JPanel gui = new JPanel(new BorderLayout(5,5));
gui.setBorder( new TitledBorder("BorderLayout(5,5)") );
JPanel plafComponents = new JPanel(
  new FlowLayout(FlowLayout.RIGHT, 3,3));
plafComponents.setBorder(
plafComponents.add(plafChooser);
plafComponents.add(pack);
gui.add(plafComponents, BorderLayout.NORTH);
JPanel dynamicLabels = new JPanel(new BorderLayout(4,4));
dynamicLabels.setBorder(
  new TitledBorder("BorderLayout(4,4)") );
gui.add( splitPane, BorderLayout.CENTER );
frame.setContentPane(gui);
frame.pack();
frame.setVisible(true);

代码示例来源:origin: kiegroup/optaplanner

return;
final JFrame exceptionFrame = new JFrame("Uncaught exception: " + e.getMessage());
Icon errorIcon = UIManager.getIcon("OptionPane.errorIcon");
BufferedImage errorImage = new BufferedImage(
errorIcon.paintIcon(null, errorImage.getGraphics(), 0, 0);
exceptionFrame.setIconImage(errorImage);
exceptionFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
JPanel contentPanel = new JPanel(new BorderLayout(5, 5));
contentPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
contentPanel.add(new JLabel("An uncaught exception has occurred: "), BorderLayout.NORTH);
contentPanel.add(stackTraceScrollPane, BorderLayout.CENTER);
stackTraceTextArea.setCaretPosition(0); // Scroll to top
JPanel buttonPanel = new JPanel(new GridLayout(1, 0));
JButton closeButton = new JButton(new AbstractAction("Close") {
  @Override
exceptionFrame.setContentPane(contentPanel);
exceptionFrame.pack();
exceptionFrame.setLocationRelativeTo(null);

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

JFrame frame = new JFrame("test");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
JPanel panel = new JPanel(new GridLayout(4,4,4,4));

for(int i=0 ; i<16 ; i++){
  JButton btn = new JButton(String.valueOf(i));
  btn.setPreferredSize(new Dimension(40, 40));
  panel.add(btn);
}
frame.setContentPane(panel);
frame.pack();
frame.setVisible(true);

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

SwingUtilities.invokeLater(new Runnable() {
  public void run() {
    JPanel p = new JPanel(new GridLayout(2,2,4,4));
    p.setBackground(Color.black);
    p.setBorder(new EmptyBorder(4,4,4,4));
    JPanel border = new JPanel(new BorderLayout());
    border.add(getLabel(
      "Border", SwingConstants.CENTER), BorderLayout.CENTER);
    p.add(border);
    JPanel gridbag = new JPanel(new GridBagLayout());
    gridbag.add(getLabel("GridBag"));
    p.add(gridbag);
    p.add(box);
    JFrame f = new JFrame("Streeeetch me..");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setContentPane(p);
    f.pack();
    f.setLocationByPlatform(true);
    f.setVisible(true);

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

cache.addChangeListener(model);
frame=new JFrame("ReplCacheDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
add(new JScrollPane(table));
JPanel key=new JPanel(new FlowLayout(FlowLayout.LEFT));
key.add(new JLabel("Key  "));
key.add(key_field);
add(key);
JPanel value=new JPanel(new FlowLayout(FlowLayout.LEFT));
value.add(new JLabel("Value"));
value.add(value_field);
add(value);
JPanel repl_count=new JPanel(new FlowLayout(FlowLayout.LEFT));
repl_count.add(new JLabel("Replication count"));
repl_count.add(repl_count_field);
perf_panel.add(perf_buttons);
frame.setContentPane(root_pane);
frame.pack();
frame.getRootPane().setDefaultButton(put_button);

代码示例来源:origin: kevin-wayne/algs4

/**
 * Displays the picture in a window on the screen.
 */
public void show() {
  // create the GUI for viewing the image if needed
  if (frame == null) {
    frame = new JFrame();
    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu("File");
    menuBar.add(menu);
    JMenuItem menuItem1 = new JMenuItem(" Save...   ");
    menuItem1.addActionListener(this);
    // use getMenuShortcutKeyMaskEx() in Java 10 (getMenuShortcutKeyMask() deprecated)           
    menuItem1.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,
                 Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    menu.add(menuItem1);
    frame.setJMenuBar(menuBar);
    frame.setContentPane(getJLabel());
    // f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    if (filename == null) frame.setTitle(width + "-by-" + height);
    else                  frame.setTitle(filename);
    frame.setResizable(false);
    frame.pack();
    frame.setVisible(true);
  }
  // draw
  frame.repaint();
}

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

Runnable r = new Runnable() {
 public void run() {
  final JFrame f = new JFrame("Test Screenshot");
  f.setJMenuBar(mb);
  JPanel p = new JPanel( new BorderLayout(5,5) );
  p.setBorder( new TitledBorder("Main GUI") );
  p.add( new JScrollPane(new JTree()),
   BorderLayout.WEST );
  p.add( new JScrollPane( new JTextArea(HELP,10,30) ),
   BorderLayout.CENTER );
  f.setContentPane( p );
  f.pack();
  f.setLocationRelativeTo(null);
  f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  f.setVisible(true);

代码示例来源:origin: cmusphinx/sphinx4

float windowShiftInMs = ps.getFloat(RaisedCosineWindower.PROP_WINDOW_SHIFT_MS);
final JFrame jframe = new JFrame("AudioTool");
fileChooser = new JFileChooser();
createMenuBar(jframe);
cepstrumPanel = new CepstrumPanel(cepstrumFrontEnd, cepstrumDataSource, audio);
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
panel.add(audioPanel);
JPanel outerPanel = new JPanel(new BorderLayout());
outerPanel.add(createButtonPanel(), BorderLayout.NORTH);
outerPanel.add(scroller);
jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jframe.setContentPane(outerPanel);
jframe.pack();
jframe.setSize(640, 400);

代码示例来源: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: stackoverflow.com

JFrame f = new JFrame();
f.setSize(500, 500);
f.setTitle("Sometimes Red, Sometimes Blue");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setContentPane(new TestPanel());
f.setVisible(true);

代码示例来源:origin: haraldk/TwelveMonkeys

public void run() {
    JFrame frame = new JFrame(pTitle);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLocationByPlatform(true);
    JPanel pane = new JPanel(new BorderLayout());
    GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
    BufferedImageIcon icon = new BufferedImageIcon(ImageUtil.accelerate(pImage, gc));
    JScrollPane scroll = new JScrollPane(new JLabel(icon));
    scroll.setBorder(null);
    pane.add(scroll);
    frame.setContentPane(pane);
    frame.pack();
    frame.setVisible(true);
  }
});

代码示例来源:origin: kevin-wayne/algs4

/**
 * Displays the picture in a window on the screen.
 */
public void show() {
  // create the GUI for viewing the image if needed
  if (frame == null) {
    frame = new JFrame();
    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu("File");
    menuBar.add(menu);
    JMenuItem menuItem1 = new JMenuItem(" Save...   ");
    menuItem1.addActionListener(this);
    // use getMenuShortcutKeyMaskEx() in Java 10 (getMenuShortcutKeyMask() deprecated)
    menuItem1.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,
                 Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    menu.add(menuItem1);
    frame.setJMenuBar(menuBar);
    frame.setContentPane(getJLabel());
    // f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    if (filename == null) frame.setTitle(width + "-by-" + height);
    else                  frame.setTitle(filename);
    frame.setResizable(false);
    frame.pack();
    frame.setVisible(true);
  }
  // draw
  frame.repaint();
}

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

JFrame frame = new JFrame("Image Example");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setContentPane(contentPane);
frame.pack();
frame.setLocationByPlatform(true);
frame.setVisible(true);

代码示例来源:origin: bobbylight/RSyntaxTextArea

public static void main(String[] args) throws Exception {
    try {
      TextEditorPane textArea = new TextEditorPane();
      textArea.load(FileLocation.create("d:/temp/test.txt"), "UTF-8");
      JPanel cp = new JPanel();
      cp.setPreferredSize(new java.awt.Dimension(300, 300));
      cp.setLayout(new java.awt.BorderLayout());
      cp.add(new JScrollPane(textArea));
      JFrame frame = new JFrame();
      frame.setContentPane(cp);
      frame.pack();
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setLocationByPlatform(true);
      frame.setVisible(true);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

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

private void displayLaunchingProgress(Process server)
    throws InterruptedException, IOException {
  final JFrame frame = new JFrame("Go Server");
  frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  frame.setContentPane(progressPane);

相关文章

JFrame类方法