List of usage examples for java.awt Frame setLayout
public void setLayout(LayoutManager mgr)
From source file:Main.java
public static void main(String[] args) { Frame f = new Frame("FlowLayout demo"); f.setLayout(new FlowLayout()); f.add(new Button("Red")); f.add(new Button("Blue")); f.add(new Button("White")); List list = new List(); for (int i = 0; i < args.length; i++) { list.add(args[i]);/*from w w w . ja va 2 s .c o m*/ } f.add(list); f.add(new Checkbox("Pick me", true)); f.add(new Label("Enter name here:")); f.add(new TextField(20)); f.pack(); f.setVisible(true); }
From source file:HelloWorld.java
public static void main(String[] args) { Frame frame = new Frame(); frame.setSize(640, 480);//from www . j av a2 s. co m frame.setLayout(new BorderLayout()); Canvas3D canvas = new Canvas3D(null); frame.add("Center", canvas); SimpleUniverse univ = new SimpleUniverse(canvas); univ.getViewingPlatform().setNominalViewingTransform(); BranchGroup scene = createSceneGraph(); scene.compile(); univ.addBranchGraph(scene); frame.show(); }
From source file:org.talend.dataprofiler.chart.util.ChartUtils.java
/** * Create a AWT_SWT bridge composite for displaying the <CODE>ChartPanel</CODE>. * /* w w w .ja v a2 s . co m*/ * @param composite * @param gd * @param chartPanel */ public static ChartPanel createAWTSWTComp(Composite composite, GridData gd, JFreeChart chart) { ChartPanel chartPanel = new ChartPanel(chart); Composite frameComp = new Composite(composite, SWT.EMBEDDED); frameComp.setLayout(new GridLayout()); frameComp.setLayoutData(gd); frameComp.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_GRAY)); Frame frame = SWT_AWT.new_Frame(frameComp); frame.setLayout(new java.awt.GridLayout()); frame.add(chartPanel); frame.validate(); return chartPanel; }
From source file:org.qsos.radar.GenerateRadar.java
/** * This class creates a composite in which the radar char will be * implemented/*from w w w .j a v a2 s .com*/ * * @param parent * Composite where the chart will be seen * @param Categories * String[] that contains the name of the elements [4 min and 7 max] the user has chosen to visualize * @param Scores * Double[] that contains the average score of each category * @return Control * */ public static Control createChart(Composite parent, String[] Categories, double[] Scores) { Composite Charcomposite = new Composite(parent, SWT.EMBEDDED); Charcomposite.setLayout(new FillLayout()); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); // for (int i = 0; i < CatNumber; i++) { dataset.addValue(Scores[i], getTitle(), Categories[i]); } String BackGroundMire = null; //Configuration of the spiderwebplot SpiderWebPlot plot = new SpiderWebPlot(); plot.setDataset(dataset); plot.setMaxValue(JQConst.RADAR_MAX_VALUE); plot.setSeriesPaint(JQConst.RADAR_SERIES_PAINT); plot.setAxisLabelGap(JQConst.RADAR_AXIS_LABEL_GAP); plot.setHeadPercent(JQConst.RADAR_HEAD_PERCENT); plot.setInteriorGap(JQConst.RADAR_INTERIOR_GAP); plot.setWebFilled(true); //The backgroundpicture used as a spiderweb is chosen according to the //number of categories selected switch (CatNumber) { case 4: BackGroundMire = JQConst.RADAR_SPIDERWEB_4; break; case 5: BackGroundMire = JQConst.RADAR_SPIDERWEB_5; break; case 6: BackGroundMire = JQConst.RADAR_SPIDERWEB_6; break; case 7: BackGroundMire = JQConst.RADAR_SPIDERWEB_7; break; } javax.swing.ImageIcon icon = new javax.swing.ImageIcon(BackGroundMire); plot.setBackgroundImage(icon.getImage()); //chart creation JFreeChart chart = new JFreeChart(plot); //Here the background color from the shell is taken in order to match AWT and SWT backgrounds Color backgroundColor = parent.getBackground(); //JFreechart doesn't support SWT so we create an AWT Frame that will depend on Charcomposite java.awt.Frame chartPanel = SWT_AWT.new_Frame(Charcomposite); chartPanel.setLayout(new java.awt.GridLayout()); ChartPanel jfreeChartPanel = new ChartPanel(chart); chartPanel.setBackground(new java.awt.Color(backgroundColor.getRed(), backgroundColor.getGreen(), backgroundColor.getBlue())); chartPanel.add(jfreeChartPanel); chartPanel.pack(); return parent; }
From source file:com.mirth.connect.plugins.rtfviewer.RTFViewer.java
@Override public void viewAttachments(List<String> attachmentIds) { // do viewing code Frame frame = new Frame("RTF Viewer"); frame.setLayout(new BorderLayout()); try {//from ww w. ja v a 2 s . co m Attachment attachment = parent.mirthClient.getAttachment(attachmentIds.get(0)); byte[] rawRTF = Base64.decodeBase64(attachment.getData()); JEditorPane jEditorPane = new JEditorPane("text/rtf", new String(rawRTF)); if (jEditorPane.getDocument().getLength() == 0) { // decoded when it should not have been. i.e.) the attachment data was not encoded. jEditorPane.setText(new String(attachment.getData())); } jEditorPane.setEditable(false); JScrollPane scrollPane = new javax.swing.JScrollPane(); scrollPane.setViewportView(jEditorPane); frame.add(scrollPane); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { e.getWindow().dispose(); } }); frame.setSize(600, 800); Dimension dlgSize = frame.getSize(); Dimension frmSize = parent.getSize(); Point loc = parent.getLocation(); if ((frmSize.width == 0 && frmSize.height == 0) || (loc.x == 0 && loc.y == 0)) { frame.setLocationRelativeTo(null); } else { frame.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y); } frame.setVisible(true); } catch (Exception e) { parent.alertException(parent, e.getStackTrace(), e.getMessage()); } }
From source file:com.mirth.connect.plugins.textviewer.TextViewer.java
@Override public void viewAttachments(String channelId, Long messageId, String attachmentId) { // do viewing code Frame frame = new Frame("Text Viewer"); frame.setLayout(new BorderLayout()); try {// w ww . j av a 2s . co m Attachment attachment = parent.mirthClient.getAttachment(channelId, messageId, attachmentId); byte[] content = Base64.decodeBase64(attachment.getContent()); boolean isRTF = attachment.getType().toLowerCase().contains("rtf"); //TODO set character encoding JEditorPane jEditorPane = new JEditorPane(isRTF ? "text/rtf" : "text/plain", new String(content)); if (jEditorPane.getDocument().getLength() == 0) { // decoded when it should not have been. i.e.) the attachment data was not encoded. jEditorPane.setText(new String(attachment.getContent())); } jEditorPane.setEditable(false); JScrollPane scrollPane = new javax.swing.JScrollPane(); scrollPane.setViewportView(jEditorPane); frame.add(scrollPane); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { e.getWindow().dispose(); } }); frame.setSize(600, 800); Dimension dlgSize = frame.getSize(); Dimension frmSize = parent.getSize(); Point loc = parent.getLocation(); if ((frmSize.width == 0 && frmSize.height == 0) || (loc.x == 0 && loc.y == 0)) { frame.setLocationRelativeTo(null); } else { frame.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y); } frame.setVisible(true); } catch (Exception e) { parent.alertThrowable(parent, e); } }
From source file:gov.redhawk.statistics.ui.views.StatisticsView.java
/** * This is a callback that will allow us to create the viewer and initialize it. *///www . j a v a 2 s . co m @Override public void createPartControl(Composite comp) { parent = comp; parent.setLayout(GridLayoutFactory.fillDefaults().margins(10, 10).numColumns(1).create()); // Custom Action for the View's Menu CustomAction customAction = new CustomAction() { @Override public void run() { SettingsDialog dialog = new SettingsDialog(parent.getShell(), datalist.length, curIndex, numBars); dialog.create(); if (dialog.open() == Window.OK) { numBars = dialog.getNumBars(); curIndex = dialog.getSelectedIndex(); refreshJob.schedule(); } } }; customAction.setText("Settings"); getViewSite().getActionBars().getMenuManager().add(customAction); // creation of chart composite and selection of associated options Composite chartComposite = new Composite(parent, SWT.EMBEDDED); chartComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create()); chart = ChartFactory.createXYBarChart(null, null, false, null, dataSet, PlotOrientation.VERTICAL, false, true, false); org.eclipse.swt.graphics.Color backgroundColor = chartComposite.getBackground(); chart.setBackgroundPaint( new Color(backgroundColor.getRed(), backgroundColor.getGreen(), backgroundColor.getBlue())); chart.getXYPlot().setBackgroundPaint(ChartColor.WHITE); Frame chartFrame = SWT_AWT.new_Frame(chartComposite); chartFrame.setBackground( new Color(backgroundColor.getRed(), backgroundColor.getGreen(), backgroundColor.getBlue())); chartFrame.setLayout(new GridLayout()); ChartPanel jFreeChartPanel = new ChartPanel(chart); chartFrame.add(jFreeChartPanel); ClusteredXYBarRenderer renderer = new ClusteredXYBarRenderer(); renderer.setBarPainter(new StandardXYBarPainter()); renderer.setMargin(0.05); renderer.setShadowVisible(false); renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelGenerator(new XYItemLabelGenerator() { @Override public String generateLabel(XYDataset dataset, int series, int item) { return String.valueOf((int) (dataset.getYValue(series, item))); } }); renderer.setBasePaint(new Color(139, 0, 0)); renderer.setLegendItemLabelGenerator(new XYSeriesLabelGenerator() { @Override public String generateLabel(XYDataset ds, int i) { if (ds.getSeriesCount() == 2) { if (i == 0) { return "Real"; } else if (i == 1) { return "Imaginary"; } else { return "Complex"; } } else if (ds.getSeriesCount() > 1) { return "Dimension " + i; } return null; } }); chart.getXYPlot().setRenderer(renderer); dataSet.addChangeListener(new DatasetChangeListener() { @Override public void datasetChanged(DatasetChangeEvent event) { chart.getPlot().datasetChanged(event); } }); // creation of the statistics composite FormToolkit toolkit = new FormToolkit(parent.getDisplay()); section = toolkit.createSection(parent, Section.DESCRIPTION | Section.NO_TITLE | Section.CLIENT_INDENT); section.setBackground(parent.getBackground()); section.setDescription(""); section.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()); // layout within parent // Composite for storing the data Composite composite = toolkit.createComposite(section, SWT.WRAP); composite.setBackground(parent.getBackground()); composite.setLayout(GridLayoutFactory.fillDefaults().margins(10, 10).numColumns(4).create()); composite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()); // layout within parent toolkit.paintBordersFor(composite); section.setClient(composite); for (int j = 0; j < STAT_PROPS.length; j++) { Label label = new Label(composite, SWT.None); label.setText(STAT_PROPS[j] + ":"); labels[j] = new Label(composite, SWT.None); labels[j].setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()); } }
From source file:net.sf.freecol.FreeCol.java
public static void startYourAddition() throws FontFormatException, IOException { Frame mainFrame; Frame mainFrame2;/*from ww w.j av a 2s.co m*/ TextField t1; TextField t2; TextField t3; TextField t4; Frame mainFrame3 = new Frame("Haha, am i middle?"); mainFrame = new Frame("Haha, am I right?!"); mainFrame.setSize(400, 400); mainFrame.setLayout(null); t1 = new TextField("Enter here"); t1.setBounds(160, 200, 150, 50); t2 = new TextField("What grade do we deserve?"); t3 = new TextField("Enter here"); t3.setBounds(160, 200, 150, 50); t4 = new TextField("What letter grade do we deserve?"); Button b = new Button("click ----->"); b.setBounds(30, 250, 130, 30); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { t2.setText("I think you meant 100"); } }); Button c = new Button("Submit"); c.setBounds(150, 250, 80, 30); c.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String in = t1.getText(); if (in.equals("100")) { t1.setText("Correct"); t1.setEditable(false); t1.setBackground(new Color(95, 216, 109)); if (t3.getText().equals("Correct")) { mainFrame3.setVisible(true); } } else { t1.setText("Wrong"); t1.setBackground(new Color(214, 81, 96)); } } }); t2.setBounds(160, 0, 175, 100); t2.setEditable(false); mainFrame.add(b); mainFrame.add(c); mainFrame.add(t1); mainFrame.add(t2); mainFrame.setLocation(1280, 0); mainFrame.setVisible(true); ///////////////The left area below and above is right mainFrame2 = new Frame("Haha, am i left?"); mainFrame2.setSize(400, 400); mainFrame2.setLayout(null); Button b2 = new Button("click ----->"); b2.setBounds(30, 250, 130, 30); b2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { t4.setText("I think you meant A"); } }); Button c2 = new Button("Submit"); c2.setBounds(150, 250, 80, 30); c2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String in = t3.getText(); if (in.equals("A")) { t3.setText("Correct"); t3.setEditable(false); t3.setBackground(new Color(95, 216, 109)); if (t1.getText().equals("Correct")) { mainFrame3.setVisible(true); } } else { t3.setText("Wrong"); t3.setBackground(new Color(214, 81, 96)); } } }); t4.setBounds(120, 0, 220, 100); t4.setEditable(false); mainFrame2.add(b2); mainFrame2.add(c2); mainFrame2.add(t3); mainFrame2.add(t4); mainFrame2.setVisible(true); //Overall correct mainFrame3.setSize(400, 400); mainFrame3.setLayout(null); mainFrame3.setLocation(640, 420); mainFrame3.setBackground(new Color(95, 216, 109)); TextField t6 = new TextField("Soooooo give us an A!!!"); t6.setBounds(160, 200, 200, 50); t6.setBackground(new Color(102, 136, 232)); mainFrame3.add(t6); }
From source file:org.carrot2.workbench.vis.aduna.AdunaClusterMapViewPage.java
private void createAdunaControl(Composite parent) { /*//ww w . j av a2 s . c om * If <code>true</code>, try some dirty hacks to avoid flicker on Windows. */ final boolean windowsFlickerHack = true; if (windowsFlickerHack) { System.setProperty("sun.awt.noerasebackground", "true"); } this.scrollable = new Composite(parent, SWT.H_SCROLL | SWT.V_SCROLL); scrollable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); final GridLayout layout = new GridLayout(); layout.marginBottom = 0; layout.marginLeft = 0; layout.marginRight = 0; layout.marginTop = 0; layout.horizontalSpacing = 0; layout.verticalSpacing = 0; layout.marginHeight = 0; layout.marginWidth = 0; scrollable.setLayout(layout); embedded = new Composite(scrollable, SWT.NO_BACKGROUND | SWT.EMBEDDED); embedded.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); final Frame frame = SWT_AWT.new_Frame(embedded); frame.setLayout(new java.awt.BorderLayout()); // LINGO-446: flicker fix; see "Creating a Root Pane Container" in http://www.eclipse.org/articles/article.php?file=Article-Swing-SWT-Integration/index.html final JApplet applet = new JApplet(); frame.add(applet); applet.setLayout(new java.awt.BorderLayout()); final JScrollPane scrollPanel = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_NEVER, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); scrollPanel.setDoubleBuffered(true); scrollPanel.setBorder(BorderFactory.createEmptyBorder()); applet.getContentPane().add(scrollPanel, java.awt.BorderLayout.CENTER); final ClusterMapFactory factory = ClusterMapFactory.createFactory(); final ClusterMap clusterMap = factory.createClusterMap(); final ClusterMapMediator mapMediator = factory.createMediator(clusterMap); this.mapMediator = mapMediator; final ClusterGraphPanel graphPanel = mapMediator.getGraphPanel(); graphPanel.setDoubleBuffered(true); scrollPanel.setViewportView(graphPanel); scrollable.addControlListener(new ControlAdapter() { @Override public void controlResized(ControlEvent e) { updateScrollBars(); } }); final SelectionAdapter adapter = new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { ScrollBar hbar = scrollable.getHorizontalBar(); ScrollBar vbar = scrollable.getVerticalBar(); final java.awt.Rectangle viewport = new java.awt.Rectangle(hbar.getSelection(), vbar.getSelection(), hbar.getThumb(), vbar.getThumb()); SwingUtilities.invokeLater(new Runnable() { public void run() { graphPanel.scrollRectToVisible(viewport); } }); } }; scrollable.getVerticalBar().addSelectionListener(adapter); scrollable.getHorizontalBar().addSelectionListener(adapter); final Runnable updateScrollBarsAsync = new Runnable() { public void run() { updateScrollBars(); } }; graphPanel.addComponentListener(new ComponentAdapter() { @Override public void componentShown(ComponentEvent e) { graphPanelSize = graphPanel.getPreferredSize(); Display.getDefault().asyncExec(updateScrollBarsAsync); } @Override public void componentResized(ComponentEvent e) { graphPanelSize = graphPanel.getPreferredSize(); Display.getDefault().asyncExec(updateScrollBarsAsync); } }); }
From source file:org.opensc.test.pkcs11.PINEntry.java
/** * Contructs a PINEntry instance. //from w ww .jav a 2s . c o m */ public PINEntry() { super(); Frame frame = new Frame("PIN entry"); frame.setLayout(new GridLayout(2, 2)); frame.add(new Label("Event:")); this.label = new Label("NO_EVENT"); frame.add(this.label); this.prompt = new Label(); frame.add(this.prompt); this.listener = new PINListener(frame); this.textField = new TextField(); this.textField.setEchoChar('*'); this.textField.addKeyListener(this.listener); frame.add(this.textField); frame.addWindowListener(this.listener); frame.pack(); frame.setVisible(true); GraphicsConfiguration gc = frame.getGraphicsConfiguration(); Rectangle r = gc.getBounds(); Point p = new Point((r.width - frame.getWidth()) / 2, (r.height - frame.getHeight()) / 2); frame.setLocation(p); }