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

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

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

JFrame.setLayout介绍

暂无

代码示例

代码示例来源: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: jMonkeyEngine/jmonkeyengine

public void show(){
  frame = new JFrame("HDR View");
  label = new JLabel(new ImageIcon(image));
  frame.getContentPane().add(label);
  frame.setLayout(new FlowLayout());
  frame.pack();
  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

import javax.swing.*;

public class BoxLayoutFoo extends JFrame {
  public BoxLayoutFoo() {

   // swap the comments below
   setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS)); // comment out this line
   //setLayout(new BoxLayout(getContentPane(), BoxLayout.LINE_AXIS)); // uncomment this line

   setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   pack();
   setVisible(true);
  }

  public static void main(String[] args) {
   new BoxLayoutFoo();
  }
}

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

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JRadioButton;

public class Rb  extends JFrame {
Rb (){
   JRadioButton male = new JRadioButton("male");
   JRadioButton female = new JRadioButton("Female");
   ButtonGroup bG = new ButtonGroup();
   bG.add(male);
   bG.add(female);
   this.setSize(100,200);
   this.setLayout( new FlowLayout());
   this.add(male);
   this.add(female);
   male.setSelected(true);
   this.setVisible(true);
 }
public static void main(String args[]){
  Rb j = new Rb();
}

代码示例来源:origin: magefree/mage

public static void main(String[] args) {
    final JFrame frame = new JFrame();
    frame.setLayout(new BorderLayout());
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    final Arrow arrow = new Arrow();
    frame.add(arrow, BorderLayout.CENTER);
    frame.setSize(640, 480);
    frame.setResizable(false);
    frame.setVisible(true);
    frame.getContentPane().addMouseMotionListener(new MouseMotionListener() {
      @Override
      public void mouseMoved(MouseEvent e) {
        arrow.setArrowLocation(320, 240, e.getX(), e.getY());
      }

      @Override
      public void mouseDragged(MouseEvent e) {
      }
    });
  }
}

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

public class JavaGui extends javax.swing.JFrame 
{
public JavaGui()
{
  setMinimumSize(1154, 753); // Make sure you do setMinimumSize() instead of setSize() when using pack() so that the JFrame does not shrink to 0 size
  setLayout(null);
  add(panelLeft);
  add(panelRight);
  pack();
}
// Next is main method

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

JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new FlowLayout(FlowLayout.CENTER, 20, 20));
frame.add(textField);
frame.pack();
frame.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);
}

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

setLayout(new FlowLayout());
label1 = new JLabel("max 10 chars");
textfield1 = new JTextField(15);
add(label1);
add(textfield1);
textfield1.setDocument(new JTextFieldLimit(10));
setVisible(true);

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

JFrame f = new JFrame("GroupPanel");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLayout(new BoxLayout(f.getContentPane(), BoxLayout.Y_AXIS));
f.add(new GroupPanel(1));
f.add(new GroupPanel(2));
f.add(Box.createVerticalGlue());
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);

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

JFrame frame = new JFrame("Test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());
frame.add(label);
frame.setSize(100, 100);

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

final JFrame frame = new JFrame();
frame.setLayout(new BorderLayout());
frame.add(textFieldA, BorderLayout.NORTH);
frame.add(textFieldB, BorderLayout.CENTER);
JButton btnGetText = new JButton("Get text");
frame.add(btnGetText, BorderLayout.SOUTH);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.pack();

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

int frameHeight = 800;
int frameWidth = 1200;
JFrame frame = new JFrame("GraphHopper UI - Small&Ugly ;)");
frame.setLayout(new BorderLayout());
frame.add(mainPanel, BorderLayout.CENTER);
frame.add(infoPanel, BorderLayout.NORTH);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(frameWidth + 10, frameHeight + 30);
frame.setVisible(true);

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

private void showHistory() {
 if (historyFrame == null) {
  historyFrame = new JFrame("Statistics History");
 } else {
  historyFrame.setVisible(false);
  historyFrame= new JFrame("Statistics History");
 }
 historyFrame.setLayout(new GridLayout(1,0));
 Object[][] entries = new Object[historyList.size()][3];
 for(int i = 0; i < historyList.size(); i++) {
  entries[i] = historyList.get(i).toArray();
 }
 DefaultTableModel tableModel = new TregexGUITableModel(entries, HistoryEntry.columnNamesArray());
 JTable statTable = new JTable(tableModel);
 DefaultTableCellRenderer dtcr = (DefaultTableCellRenderer) statTable.getDefaultRenderer(String.class);
 dtcr.setHorizontalAlignment(DefaultTableCellRenderer.CENTER);
 JScrollPane scroller = new JScrollPane(statTable);
 historyFrame.add(scroller);
 historyFrame.pack();
 historyFrame.setLocationRelativeTo(TregexGUI.getInstance());
 historyFrame.setBackground(Color.WHITE);
 historyFrame.setVisible(true);
 historyFrame.repaint();
}

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

setLayout(new BorderLayout());
this.panel = new JPanel();
this.panel.setLayout(new FlowLayout());
add(panel, BorderLayout.CENTER);
JButton button = new JButton("CLICK HERE");
add(button, BorderLayout.SOUTH);
button.addActionListener(this);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(500, 500);
setVisible(true);
this.panel.add(new JButton("Button"));
this.panel.revalidate();
validate();

代码示例来源:origin: RipMeApp/ripme

public MainWindow() {
  mainFrame = new JFrame("RipMe v" + UpdateUtils.getThisJarVersion());
  mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  mainFrame.setLayout(new GridBagLayout());
  createUI(mainFrame.getContentPane());
  pack();
  loadHistory();
  setupHandlers();
  Thread shutdownThread = new Thread(this::shutdownCleanup);
  Runtime.getRuntime().addShutdownHook(shutdownThread);
  if (Utils.getConfigBoolean("auto.update", true)) {
    upgradeProgram();
  }
  boolean autoripEnabled = Utils.getConfigBoolean("clipboard.autorip", false);
  ClipboardUtils.setClipboardAutoRip(autoripEnabled);
  trayMenuAutorip.setState(autoripEnabled);
}

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

private JFrame frame = new JFrame();
private JLayeredPane lpane = new JLayeredPane();
private JPanel panelBlue = new JPanel();
  frame.setLayout(new BorderLayout());
  frame.add(lpane, BorderLayout.CENTER);
  lpane.setBounds(0, 0, 600, 400);

相关文章

JFrame类方法