下面列出了javax.swing.JFrame#getContentPane ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static void main(String[] args) {
final Font font = new Font("monospace", Font.PLAIN, 12);
final JFrame frame = new JFrame();
final TestBigLayoutModel model =
new TestBigLayoutModel(frame.getFontMetrics(font), "AAA", BigInteger.valueOf(1000000L));
final FieldPanel provider = new FieldPanel(model);
IndexedScrollPane scrollPanel = new IndexedScrollPane(provider);
Container contentPane = frame.getContentPane();
contentPane.setLayout(new BorderLayout());
contentPane.add(scrollPanel);
JButton button = new JButton("Hit Me");
button.addActionListener(e -> model.updateData(1000, 2000));
contentPane.add(button, BorderLayout.SOUTH);
frame.pack();
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.repaint();
}
public static void main(String[] args) throws Exception {
final JFrame jFrame = new JFrame("Output parameter Definition Form");
Container contentPane = jFrame.getContentPane();
if (args.length == 0) {
throw new IllegalArgumentException("Missing argument to product file.");
}
Product sourceProduct = ProductIO.readProduct(args[0]);
CoordinateReferenceSystem targetCrs = CRS.decode("EPSG:32632");
OutputGeometryFormModel model = new OutputGeometryFormModel(sourceProduct, targetCrs);
OutputGeometryForm form = new OutputGeometryForm(model);
contentPane.add(form);
jFrame.setSize(400, 600);
jFrame.setLocationRelativeTo(null);
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
jFrame.setVisible(true);
}
});
}
public static void showDendrogram(final HierarchicalClusterer clusterer) throws Exception {
final String timeStamp = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new Date());
final JFrame mainFrame = new JFrame("Dendrogram " + timeStamp);
mainFrame.setSize(1024, 768);
mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
final Container content = mainFrame.getContentPane();
content.setLayout(new GridLayout(1, 1));
final HierarchyVisualizer visualizer = new HierarchyVisualizer(clusterer.graph());
content.add(visualizer);
mainFrame.setVisible(true);
}
public static void createUI() {
f = new JFrame("LinearGradient Printing Test");
f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
final LinearGradientPrintingTest gpt = new LinearGradientPrintingTest();
Container c = f.getContentPane();
c.add(BorderLayout.CENTER, gpt);
final JButton print = new JButton("Print");
print.addActionListener(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(gpt);
final boolean doPrint = job.printDialog();
if (doPrint) {
try {
job.print();
} catch (PrinterException ex) {
throw new RuntimeException(ex);
}
}
}
});
c.add(print, BorderLayout.SOUTH);
f.pack();
f.setVisible(true);
}
private static void showUI() {
frame = new JFrame();
frame.setSize(new Dimension(400, 400));
frame.setLocationRelativeTo(null);
final Container content = frame.getContentPane();
content.setLayout(new BorderLayout(0, 0));
Container lastPanel = content;
for (int i = 0; i < 500; i++) {
final JPanel p = new JPanel();
p.setLayout(new BorderLayout(0, 0));
lastPanel.add(p);
lastPanel.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
System.out.println("click");
go.countDown();
}
});
lastPanel = p;
}
lastPanel.setBackground(Color.GREEN);
frame.setVisible(true);
Point loc = frame.getLocationOnScreen();
center.x = loc.x + frame.getWidth() / 2;
center.y = loc.y + frame.getHeight() / 2;
}
/**
* Contructs the layout with a container for displaying chart and a control
* panel for selecting interactivity.
*
* @param args
*/
public static void main( String[] args )
{
final Regression_142403_swing siv = new Regression_142403_swing( );
JFrame jf = new JFrame( );
jf.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
jf.addComponentListener( siv );
Container co = jf.getContentPane( );
co.setLayout( new BorderLayout( ) );
co.add( siv, BorderLayout.CENTER );
Dimension dScreen = Toolkit.getDefaultToolkit( ).getScreenSize( );
Dimension dApp = new Dimension( 600, 400 );
jf.setSize( dApp );
jf.setLocation(
( dScreen.width - dApp.width ) / 2,
( dScreen.height - dApp.height ) / 2 );
jf.setTitle( siv.getClass( ).getName( ) + " [device=" //$NON-NLS-1$
+ siv.idr.getClass( ).getName( ) + "]" );//$NON-NLS-1$
ControlPanel cp = siv.new ControlPanel( siv );
co.add( cp, BorderLayout.SOUTH );
siv.idr.setProperty( IDeviceRenderer.UPDATE_NOTIFIER, siv );
jf.addWindowListener( new WindowAdapter( ) {
public void windowClosing( WindowEvent e )
{
siv.idr.dispose( );
}
} );
jf.setVisible( true );
}
public static void createUI() {
f = new JFrame("RadialGradient Printing Test");
f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
final RadialGradientPrintingTest gpt = new RadialGradientPrintingTest();
Container c = f.getContentPane();
c.add(BorderLayout.CENTER, gpt);
final JButton print = new JButton("Print");
print.addActionListener(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(gpt);
final boolean doPrint = job.printDialog();
if (doPrint) {
try {
job.print();
} catch (PrinterException ex) {
throw new RuntimeException(ex);
}
}
}
});
c.add(print, BorderLayout.SOUTH);
f.pack();
f.setVisible(true);
}
public static void displayDendrogram(String graph) {
JFrame frame = new JFrame("Dendrogram");
frame.setSize(500, 400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container pane = frame.getContentPane();
pane.setLayout(new BorderLayout());
pane.add(new HierarchyVisualizer(graph));
frame.setVisible(true);
}
/**
* Constructs the layout with a container for displaying chart and a control
* panel for selecting interactivity.
*
* @param args
*/
public static void main( String[] args )
{
final SwingShowTooltipViewer siv = new SwingShowTooltipViewer( );
JFrame jf = new JFrame( );
jf.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
jf.addComponentListener( siv );
Container co = jf.getContentPane( );
co.setLayout( new BorderLayout( ) );
co.add( siv, BorderLayout.CENTER );
Dimension dScreen = Toolkit.getDefaultToolkit( ).getScreenSize( );
Dimension dApp = new Dimension( 600, 400 );
jf.setSize( dApp );
jf.setLocation(
( dScreen.width - dApp.width ) / 2,
( dScreen.height - dApp.height ) / 2 );
jf.setTitle( siv.getClass( ).getName( ) + " [device=" //$NON-NLS-1$
+ siv.idr.getClass( ).getName( ) + "]" );//$NON-NLS-1$
ControlPanel cp = siv.new ControlPanel( siv );
co.add( cp, BorderLayout.SOUTH );
siv.idr.setProperty( IDeviceRenderer.UPDATE_NOTIFIER, siv );
jf.addWindowListener( new WindowAdapter( ) {
@Override
public void windowClosing( WindowEvent e )
{
siv.idr.dispose( );
}
} );
jf.setVisible( true );
}
public static void createUI() {
f = new JFrame("LinearGradient Printing Test");
f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
final LinearGradientPrintingTest gpt = new LinearGradientPrintingTest();
Container c = f.getContentPane();
c.add(BorderLayout.CENTER, gpt);
final JButton print = new JButton("Print");
print.addActionListener(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(gpt);
final boolean doPrint = job.printDialog();
if (doPrint) {
try {
job.print();
} catch (PrinterException ex) {
throw new RuntimeException(ex);
}
}
}
});
c.add(print, BorderLayout.SOUTH);
f.pack();
f.setVisible(true);
}
public static void createUI() {
f = new JFrame("RadialGradient Printing Test");
f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
final RadialGradientPrintingTest gpt = new RadialGradientPrintingTest();
Container c = f.getContentPane();
c.add(BorderLayout.CENTER, gpt);
final JButton print = new JButton("Print");
print.addActionListener(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(gpt);
final boolean doPrint = job.printDialog();
if (doPrint) {
try {
job.print();
} catch (PrinterException ex) {
throw new RuntimeException(ex);
}
}
}
});
c.add(print, BorderLayout.SOUTH);
f.pack();
f.setVisible(true);
}
/**
* Contructs the layout with a container for displaying chart and a control
* panel for selecting interactivity.
*
* @param args
*/
public static void main( String[] args )
{
final Regression_124765_swing siv = new Regression_124765_swing( );
JFrame jf = new JFrame( );
jf.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
jf.addComponentListener( siv );
Container co = jf.getContentPane( );
co.setLayout( new BorderLayout( ) );
co.add( siv, BorderLayout.CENTER );
Dimension dScreen = Toolkit.getDefaultToolkit( ).getScreenSize( );
Dimension dApp = new Dimension( 600, 400 );
jf.setSize( dApp );
jf.setLocation(
( dScreen.width - dApp.width ) / 2,
( dScreen.height - dApp.height ) / 2 );
jf.setTitle( siv.getClass( ).getName( ) + " [device=" //$NON-NLS-1$
+ siv.idr.getClass( ).getName( ) + "]" );//$NON-NLS-1$
ControlPanel cp = siv.new ControlPanel( siv );
co.add( cp, BorderLayout.SOUTH );
siv.idr.setProperty( IDeviceRenderer.UPDATE_NOTIFIER, siv );
jf.addWindowListener( new WindowAdapter( ) {
public void windowClosing( WindowEvent e )
{
siv.idr.dispose( );
}
} );
jf.setVisible( true );
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frmMiPrimerFrame = new JFrame();
frmMiPrimerFrame.setTitle("Mi Primer Frame");
frmMiPrimerFrame.setBounds(100, 100, 686, 472);
frmMiPrimerFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
desktopPane = new JDesktopPane();
GroupLayout groupLayout = new GroupLayout(frmMiPrimerFrame.getContentPane());
groupLayout.setHorizontalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addContainerGap()
.addComponent(desktopPane, GroupLayout.DEFAULT_SIZE, 206, Short.MAX_VALUE)
.addContainerGap())
);
groupLayout.setVerticalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addContainerGap()
.addComponent(desktopPane, GroupLayout.DEFAULT_SIZE, 234, Short.MAX_VALUE)
.addContainerGap())
);
frmMiPrimerFrame.getContentPane().setLayout(groupLayout);
JMenuBar menuBar = new JMenuBar();
frmMiPrimerFrame.setJMenuBar(menuBar);
JMenu mnArchivo = new JMenu("Archivo");
menuBar.add(mnArchivo);
JMenuItem mntmNuevoSaludo = new JMenuItem("Nuevo Saludo");
mntmNuevoSaludo.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
abrirNuevoSaludo();
}
});
mnArchivo.add(mntmNuevoSaludo);
}
/**
* Contructs the layout with a container for displaying chart and a control
* panel for selecting interactivity.
*
* @param args
*/
public static void main( String[] args )
{
final SwingHighlightViewer siv = new SwingHighlightViewer( );
JFrame jf = new JFrame( );
jf.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
jf.addComponentListener( siv );
Container co = jf.getContentPane( );
co.setLayout( new BorderLayout( ) );
co.add( siv, BorderLayout.CENTER );
Dimension dScreen = Toolkit.getDefaultToolkit( ).getScreenSize( );
Dimension dApp = new Dimension( 600, 400 );
jf.setSize( dApp );
jf.setLocation(
( dScreen.width - dApp.width ) / 2,
( dScreen.height - dApp.height ) / 2 );
jf.setTitle( siv.getClass( ).getName( ) + " [device=" //$NON-NLS-1$
+ siv.idr.getClass( ).getName( ) + "]" );//$NON-NLS-1$
ControlPanel cp = siv.new ControlPanel( siv );
co.add( cp, BorderLayout.SOUTH );
siv.idr.setProperty( IDeviceRenderer.UPDATE_NOTIFIER, siv );
jf.addWindowListener( new WindowAdapter( ) {
@Override
public void windowClosing( WindowEvent e )
{
siv.idr.dispose( );
}
} );
jf.setVisible( true );
}
private static void createAndShowGUI(JPanel jtop) {
JFrame frame = new JFrame("GfxdTop");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JComponent contentPane = (JComponent) frame.getContentPane();
contentPane.add(jtop, BorderLayout.CENTER);
contentPane.setOpaque(true);
contentPane.setBorder(new EmptyBorder(12, 12, 12, 12));
frame.setContentPane(contentPane);
frame.pack();
frame.setVisible(true);
}
private static void printTexture() {
f = new JFrame("Texture Printing Test");
f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
final TexturePaintPrintingTest gpt = new TexturePaintPrintingTest();
Container c = f.getContentPane();
c.add(BorderLayout.CENTER, gpt);
final JButton print = new JButton("Print");
print.addActionListener(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(gpt);
final boolean doPrint = job.printDialog();
if (doPrint) {
try {
job.print();
} catch (PrinterException ex) {
throw new RuntimeException(ex);
}
}
}
});
c.add(print, BorderLayout.SOUTH);
f.pack();
f.setVisible(true);
}
public static void createUI() {
f = new JFrame("RadialGradient Printing Test");
f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
final RadialGradientPrintingTest gpt = new RadialGradientPrintingTest();
Container c = f.getContentPane();
c.add(BorderLayout.CENTER, gpt);
final JButton print = new JButton("Print");
print.addActionListener(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(gpt);
final boolean doPrint = job.printDialog();
if (doPrint) {
try {
job.print();
} catch (PrinterException ex) {
throw new RuntimeException(ex);
}
}
}
});
c.add(print, BorderLayout.SOUTH);
f.pack();
f.setVisible(true);
}
public TestImage()
{
JFrame frame = new JFrame(getClass().toString());
Container pane = frame.getContentPane();
pane.setLayout(new BorderLayout());
pane.add(this);
image = decodeImage(new String[] {
"----------------------------------------------------------------------------",
"----------------------------------------------------------------------------",
"----------------------------------------------------------------------------",
"----------------------------------------------------------------------------",
"----####---------------####---------------####---------------####-----------",
"--------##-----------------##-----------------##-----------------##---------",
"----------####---------------####---------------####---------------####-----",
"--------------#------------------#------------------#------------------#----",
"--------------#------------------#------------------#------------------#----",
"----------------------------------------------------------------------------",
"---#############------#############------#############------#############---",
"---#############------#############------#############------#############---",
"----------------------------------------------------------------------------",
"----------------------------------------------------------------------------",
"----####---------------####---------------####---------------####-----------",
"--------##-----------------##-----------------##-----------------##---------",
"----------####---------------####---------------####---------------####-----",
"--------------#------------------#------------------#------------------#----",
"--------------#------------------#------------------#------------------#----",
"----------------------------------------------------------------------------",
"---#############------#############------#############------#############---",
"---#############------#############------#############------#############---",
"----------------------------------------------------------------------------",
"----------------------------------------------------------------------------",
"----####---------------####---------------####---------------####-----------",
"--------##-----------------##-----------------##-----------------##---------",
"----------####---------------####---------------####---------------####-----",
"--------------#------------------#------------------#------------------#----",
"--------------#------------------#------------------#------------------#----",
"----------------------------------------------------------------------------",
"---#############------#############------#############------#############---",
"---#############------#############------#############------#############---",
"----------------------------------------------------------------------------",
"----------------------------------------------------------------------------"
});
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocation(100, 100);
frame.pack();
frame.setSize(100, 100);
frame.setVisible(true);
}
public void createAndShowUI() {
BoundedRangeModel progressModel = new DefaultBoundedRangeModel();
BoundedRangeProgress progressAdapter = new BoundedRangeProgress(progressModel);
Document resultDocument = new PlainDocument();
ComponentVisibility progressBarVisibility = new ComponentVisibility("enabled", false);
progressBarVisibility.setInvisibleDelay(1, TimeUnit.SECONDS);
ProgressCancelAction cancelAction = new ProgressCancelAction();
cancelAction.putValue(Action.NAME, "Cancel");
ProgressSimulationAction progressAction = new ProgressSimulationAction();
progressAction.addProgressAware(progressAdapter);
progressAction.addProgressAware(cancelAction);
progressAction.addPropertyChangeListener(progressBarVisibility);
progressAction.putValue(Action.NAME, "Start");
progressAction.setResultDocument(resultDocument);
JFrame mainFrame = new JFrame("Progress Object Pattern with Java Swing");
mainFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
mainFrame.setMinimumSize(new Dimension(600, 120));
JProgressBar progressBar = new JProgressBar(progressModel);
progressBar.setVisible(false);
progressBar.setStringPainted(true);
progressBarVisibility.setComponent(progressBar);
JButton startProgressButton = new JButton(progressAction);
JButton cancelButton = new JButton(cancelAction);
JTextField resultTextField = new JTextField(40);
resultTextField.setEditable(false);
resultTextField.setDocument(resultDocument);
JPanel mainPanel = new JPanel();
mainPanel.add(startProgressButton);
mainPanel.add(cancelButton);
mainPanel.add(resultTextField);
Container contentPane = mainFrame.getContentPane();
contentPane.add(mainPanel);
contentPane.add(progressBar, BorderLayout.SOUTH);
mainFrame.pack();
mainFrame.setLocationRelativeTo(null);
mainFrame.setVisible(true);
}
static public void main(String[] args) {
if(args.length != 2) {
System.err.println(
"Usage: java AppenderTable bufferSize runLength\n"
+" where bufferSize is the size of the cyclic buffer in the TableModel\n"
+" and runLength is the total number of elements to add to the table in\n"
+" this test run.");
return;
}
JFrame frame = new JFrame("JTableAppennder test");
Container container = frame.getContentPane();
AppenderTable tableAppender = new AppenderTable();
int bufferSize = Integer.parseInt(args[0]);
AppenderTableModel model = new AppenderTableModel(bufferSize);
tableAppender.setModel(model);
int runLength = Integer.parseInt(args[1]);
JScrollPane sp = new JScrollPane(tableAppender);
sp.setPreferredSize(new Dimension(250, 80));
container.setLayout(new BoxLayout(container, BoxLayout.X_AXIS));
container.add(sp);
// The "ADD" button is intended for manual testing. It will
// add one new logging event to the table.
JButton button = new JButton("ADD");
container.add(button);
button.addActionListener(new JTableAddAction(tableAppender));
frame.setSize(new Dimension(500,300));
frame.setVisible(true);
long before = System.currentTimeMillis();
int i = 0;
while(i++ < runLength) {
LoggingEvent event = new LoggingEvent("x", logger, Level.ERROR,
"Message "+i, null);
tableAppender.doAppend(event);
}
long after = System.currentTimeMillis();
long totalTime = (after-before);
System.out.println("Total time :"+totalTime+ " milliseconds for "+
"runLength insertions.");
System.out.println("Average time per insertion :"
+(totalTime*1000/runLength)+ " micro-seconds.");
}