本文整理了Java中javax.swing.JFrame.pack()
方法的一些代码示例,展示了JFrame.pack()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JFrame.pack()
方法的具体详情如下:
包路径:javax.swing.JFrame
类名称:JFrame
方法名: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: osmdroid/osmdroid
public static void main(final String[] args) {
final JFrame j = new OSMMapTilePackagerUI();
j.setPreferredSize(new Dimension(640, 400));
j.setDefaultCloseOperation(EXIT_ON_CLOSE);
j.pack();
j.setVisible(true);
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
public void run(){
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
createFrame();
currentPanel.add(canvas, BorderLayout.CENTER);
frame.pack();
startApp();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
代码示例来源:origin: 4thline/cling
@Override
public void run() {
errorWindow.getContentPane().removeAll();
JTextArea textArea = new JTextArea();
textArea.setEditable(false);
StringBuilder text = new StringBuilder();
text.append("An exceptional error occurred!\nYou can try to continue or exit the application.\n\n");
text.append("Please tell us about this here:\nhttp://www.4thline.org/projects/mailinglists-cling.html\n\n");
text.append("-------------------------------------------------------------------------------------------------------------\n\n");
Writer stackTrace = new StringWriter();
throwable.printStackTrace(new PrintWriter(stackTrace));
text.append(stackTrace.toString());
textArea.setText(text.toString());
JScrollPane pane = new JScrollPane(textArea);
errorWindow.getContentPane().add(pane, BorderLayout.CENTER);
JButton exitButton = new JButton("Exit Application");
exitButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.exit(1);
}
});
errorWindow.getContentPane().add(exitButton, BorderLayout.SOUTH);
errorWindow.pack();
Application.center(errorWindow);
textArea.setCaretPosition(0);
errorWindow.setVisible(true);
}
});
代码示例来源:origin: stackoverflow.com
JFrame jf = new JFrame();
JPanel jp = new JPanel();
jp.setPreferredSize(new Dimension(400,800));// changed it to preferredSize, Thanks!
jf.getContentPane().add( jp );// adding to content pane will work here. Please read the comment bellow.
jf.pack();
代码示例来源: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: 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
private void makeGUI()
{
final JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().setLayout(new FlowLayout());
// include: "class AnswerWorker" code here.
// include: "JButton" b code here.
f.getContentPane().add(b);
f.getContentPane().add(new JButton("Nothing"));
f.pack();
f.setVisible(true);
}
代码示例来源:origin: stackoverflow.com
JFrame frame = new JFrame("FooRendererTest");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(mainPanel); // or whatever...
frame.pack();
frame.setLocationRelativeTo(null); // *** this will center your app ***
frame.setVisible(true);
代码示例来源: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
public static void main(String[] args) throws MalformedURLException {
URL url = new URL("<URL to your Animated GIF>");
Icon icon = new ImageIcon(url);
JLabel label = new JLabel(icon);
JFrame f = new JFrame("Animation");
f.getContentPane().add(label);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
}
代码示例来源:origin: loklak/loklak_server
/**
* show the image as JFrame on desktop
*/
public void show() {
JLabel label = new JLabel(new ImageIcon(this.image));
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(label);
f.pack();
f.setVisible(true);
}
代码示例来源:origin: stackoverflow.com
JFrame jFrame = new JFrame("Test");
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//jFrame.setLocationRelativeTo(null);
jFrame.setSize(600, 600);
jFrame.pack();
jFrame.setVisible(true);
jFrame.setLocationRelativeTo(null); //To center the code
代码示例来源: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: 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: 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.getContentPane().setLayout(new FlowLayout());
frame.getContentPane().add(new JLabel(new ImageIcon(img)));
frame.getContentPane().add(new JLabel(new ImageIcon(img2)));
frame.getContentPane().add(new JLabel(new ImageIcon(img3)));
frame.pack();
frame.setVisible(true);
//frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // if you want the X button to close the app
代码示例来源: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: jMonkeyEngine/jmonkeyengine
private static void createWindowForPanel(AwtPanel panel, int location){
JFrame frame = new JFrame("Render Display " + location);
frame.getContentPane().setLayout(new BorderLayout());
frame.getContentPane().add(panel, BorderLayout.CENTER);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent e) {
if (++panelsClosed == 2){
app.stop();
}
}
});
frame.pack();
frame.setLocation(location, Toolkit.getDefaultToolkit().getScreenSize().height - 400);
frame.setVisible(true);
}
内容来源于网络,如有侵权,请联系作者删除!