List of usage examples for javax.swing JPanel setPreferredSize
@BeanProperty(preferred = true, description = "The preferred size of the component.") public void setPreferredSize(Dimension preferredSize)
From source file:Main.java
public static void main(String[] args) { JPanel bottomPanel = new JPanel(); bottomPanel.add(new JButton("Bottom Button")); bottomPanel.setBorder(BorderFactory.createTitledBorder("Bottom Panel")); JPanel centerPanel = new JPanel(); centerPanel.setBorder(BorderFactory.createTitledBorder("Center Panel")); JPanel mainPanel = new JPanel(new BorderLayout()); mainPanel.add(centerPanel, BorderLayout.CENTER); mainPanel.add(bottomPanel, BorderLayout.PAGE_END); int eb = 25;//from w w w . j ava 2 s . c om mainPanel.setBorder(BorderFactory.createEmptyBorder(eb, eb, eb, eb)); mainPanel.setPreferredSize(new Dimension(500, 400)); JFrame frame = new JFrame("Main"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setContentPane(mainPanel); frame.pack(); frame.setLocationByPlatform(true); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); JPanel panel = new JPanel(); JTextPane textPane = new JTextPane(); JButton button = new JButton("Test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); panel.setLayout(new BorderLayout()); panel.setPreferredSize(new Dimension(200, 200)); panel.add(textPane, BorderLayout.CENTER); panel.add(button, BorderLayout.SOUTH); textPane.addStyle("myStyle", null); button.addActionListener(e -> {//from w w w . ja va 2 s . co m StyledDocument doc = textPane.getStyledDocument(); int start = textPane.getSelectionStart(); int end = textPane.getSelectionEnd(); if (start == end) { return; } if (start > end) { int life = start; start = end; end = life; } Style style = textPane.getStyle("myStyle"); if (StyleConstants.isBold(style)) { StyleConstants.setBold(style, false); } else { StyleConstants.setBold(style, true); } doc.setCharacterAttributes(start, end - start, style, false); }); frame.add(panel); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); }
From source file:moviedatas.MovieDatas.java
public static void main(String[] args) { FilterController fpc = new FilterController(); SortController spc = new SortController(); //1. Create the frame. JFrame frame = new JFrame("Movies Open Datas by Harp-e"); frame.setPreferredSize(new Dimension(1280, 800)); //2. Optional: What happens when the frame closes? frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); MovieListView movieListView = new MovieListView(); JPanel movieListPanel = movieListView.createViewPanel(); TitledBorder moviesTitle;// w w w. ja v a2 s .co m moviesTitle = BorderFactory.createTitledBorder("Movies"); movieListPanel.setBorder(moviesTitle); //3. Create components and put them in the frame. //---------------------------------------------------------------------- // Sort & Filter panel (right) //---------------------------------------------------------------------- SortPanelView sortFilterView = new SortPanelView(); FilterPanelView filterPanelView = new FilterPanelView(); JPanel sortPanel = sortFilterView.createSortPanel(); JPanel filterPanel = filterPanelView.createFilterPanel(); JPanel sortFilterPanel = new JPanel(); sortFilterPanel.setLayout(new BoxLayout(sortFilterPanel, BoxLayout.PAGE_AXIS)); sortFilterPanel.add(sortPanel); sortFilterPanel.add(filterPanel); frame.getContentPane().add(sortFilterPanel, BorderLayout.WEST); //---------------------------------------------------------------------- // Movie Info Panel (left) //---------------------------------------------------------------------- MovieInfoController movieInfoController = new MovieInfoController(); JPanel movieInfoView = movieInfoController.initView(); TitledBorder infoTitle; infoTitle = BorderFactory.createTitledBorder("Informations"); movieInfoView.setBorder(infoTitle); //---------------------------------------------------------------------- // Movie List Panel (middle) //---------------------------------------------------------------------- JPanel listPanel = new JPanel(); listPanel.setLayout(new BorderLayout()); listPanel.setPreferredSize(new Dimension(1280, 400)); listPanel.add(sortFilterPanel, BorderLayout.WEST); listPanel.add(movieInfoView, BorderLayout.EAST); listPanel.add(movieListPanel, BorderLayout.CENTER); frame.getContentPane().add(listPanel, BorderLayout.NORTH); //---------------------------------------------------------------------- // Charts Panel (bottom) //---------------------------------------------------------------------- JPanel chartPanel = new JPanel(); // Spider chart Panel //______________________________________________________________________ // Create the panel JPanel spiderPanel = new JPanel(); // Create the view SpiderChartView spiderChartView = new SpiderChartView(); // Create a tilte TitledBorder spiderTitle; // Put a border around the title spiderTitle = BorderFactory.createTitledBorder("Spider chart"); // Put the border on the panel spiderPanel.setBorder(spiderTitle); // Put the view on the panel spiderPanel.add(spiderChartView.initView()); // Put the spider panel on the global panel chartPanel.add(spiderPanel); //______________________________________________________________________ // Bar chart Panel //______________________________________________________________________ JPanel barPanel = new JPanel(); BarChartView barChartView = new BarChartView(); TitledBorder barTitle; barTitle = BorderFactory.createTitledBorder("Bar chart"); barPanel.setBorder(barTitle); barPanel.add(barChartView.initView()); chartPanel.add(barPanel); //______________________________________________________________________ // Global chart Panel //______________________________________________________________________ JPanel globalChartPanel = new JPanel(); GlobalChart globalChartView = new GlobalChart(); TitledBorder globalTitle; globalTitle = BorderFactory.createTitledBorder("Global chart"); globalChartPanel.setBorder(globalTitle); globalChartPanel.add(globalChartView.initView()); chartPanel.add(globalChartPanel); //______________________________________________________________________ frame.getContentPane().add(chartPanel, BorderLayout.CENTER); //---------------------------------------------------------------------- //4. Size the frame. frame.pack(); //5. Show it. frame.setVisible(true); //ArrayList<Movie> movies = new ArrayList<>(); //FilterController.filter(10,SortController.byTitle(movies)); }
From source file:com.github.lucapino.sheetmaker.PreviewJFrame.java
public static void main(String[] args) { System.setProperty("awt.useSystemAAFontSettings", "on"); System.setProperty("swing.aatext", "true"); SwingUtilities.invokeLater(new Runnable() { @Override//from w w w . j ava 2 s . c o m public void run() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); File tmpFolder = new File("/tmp/images"); tmpFolder.mkdir(); String coverPath = tmpFolder.getAbsolutePath().replaceAll("\\\\", "/") + "/cover.jpg"; String backdropPath = tmpFolder.getAbsolutePath().replaceAll("\\\\", "/") + "/backdrop.jpg"; String fanart1Path = tmpFolder.getAbsolutePath().replaceAll("\\\\", "/") + "/fanart1.jpg"; String fanart2Path = tmpFolder.getAbsolutePath().replaceAll("\\\\", "/") + "/fanart2.jpg"; String fanart3Path = tmpFolder.getAbsolutePath().replaceAll("\\\\", "/") + "/fanart3.jpg"; PreviewJFrame frame = new PreviewJFrame(); logger.info("Creating parser..."); InfoRetriever parser = new MediaInfoRetriever(); MovieInfo movieInfo = parser.getMovieInfo("/media/tagliani/Elements/Film/JackRyan.mkv"); logger.info("Retrieving movie file info..."); logger.info("Creating dataretriever..."); DataRetriever retriever = new DataRetrieverImpl(); logger.info("Retrieving movie data..."); Movie movie = retriever.retrieveMovieFromImdbID("tt1205537", "IT"); logger.info("Retrieving backdrops and fanart..."); List<Artwork> images = movie.getBackdrops(); // background logger.info("Saving backdrop..."); IOUtils.copyLarge(new URL(images.get(0).getImageURL()).openStream(), new FileOutputStream(backdropPath)); for (int i = 1; i < 4; i++) { // fanart1 // fanart2 // fanart3 String imageURL = images.get(i).getImageURL(); logger.info("Saving fanart{}...", i); IOUtils.copyLarge(new URL(imageURL).openStream(), new FileOutputStream(tmpFolder.getAbsolutePath() + "/fanart" + i + ".jpg")); } // cover logger.info("Retrieving cover..."); Artwork cover = movie.getPosters().get(0); String imageURL = cover.getImageURL(); logger.info("Saving cover..."); IOUtils.copyLarge(new URL(imageURL).openStream(), new FileOutputStream(coverPath)); Map<String, String> tokenMap = TemplateFilter.createTokenMap(movie, movieInfo, null); logger.info("Creating renderer..."); JavaTemplateRenderer renderer = new JavaTemplateRenderer(); JPanel imagePanel = null; try { logger.info("Rendering image..."); imagePanel = renderer.renderTemplate( this.getClass().getResource("/templates/simplicity/template.xml"), tokenMap, backdropPath, fanart1Path, fanart2Path, fanart3Path, coverPath); logger.info("Adding image to frame..."); frame.add(imagePanel); } catch (Exception ex) { ex.printStackTrace(); } imagePanel.setPreferredSize(new Dimension(imagePanel.getWidth(), imagePanel.getHeight())); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.setVisible(true); frame.pack(); logger.info("Creating image for save..."); BufferedImage imageTosave = ScreenImage.createImage(imagePanel); logger.info("Saving image..."); ScreenImage.writeImage(imageTosave, "/tmp/images/final.png"); logger.info("Image saved..."); } catch (Exception ex) { logger.error("Error: ", ex); } } }); }
From source file:Main.java
public static void main(String[] args) { JPanel gui = new JPanel(new BorderLayout()); String HTML = "<html>" + "<head>" + "<style type=text/css>" + "body {" + " background-image: http://www.java2s.com/style/download.png;" + " background-repeat:no-repeat;" + " background-position:left top;" + " background-attachment: scroll;" + " color: #BBBBBB;" + "}" + "</style>" + "</head>" + "<body>" + "<h1>Heading 1</h1>"; String PARAGRAPH = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean eu nulla urna. Donec sit amet risus nisl, a porta enim. Quisque luctus, ligula eu scelerisque gravida, tellus quam vestibulum urna, ut aliquet sapien purus sed erat. Pellentesque consequat vehicula magna, eu aliquam magna interdum porttitor. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed sollicitudin sapien non leo tempus lobortis. Morbi semper auctor ipsum, a semper quam elementum a. Aliquam eget sem metus."; gui.setPreferredSize(new Dimension(400, 100)); StringBuilder sb = new StringBuilder(); sb.append(HTML);/*www .j a v a2s. c o m*/ for (int ii = 0; ii < 10; ii++) { sb.append("<h2>Header 2</h2>"); sb.append(PARAGRAPH); } JEditorPane jep = new JEditorPane(); jep.setOpaque(false); jep.setContentType("text/html"); jep.setText(sb.toString()); JScrollPane jsp = new JScrollPane(jep) { BufferedImage bg = new BufferedImage(350, 50, BufferedImage.TYPE_INT_RGB); @Override public void paintComponent(Graphics g) { super.paintComponent(g); g.drawImage(bg, 0, 0, this); } }; jsp.getViewport().setOpaque(false); gui.add(jsp); Main bih = new Main(); JFrame f = new JFrame(); f.add(gui); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.pack(); f.setVisible(true); }
From source file:Main.java
/** Resize the panel correctly, based on size of things in it. We're assuming that sqlEdit has been added to the panel as well. */ public static void resizeJPanel(JPanel p) { Dimension d = p.getLayout().preferredLayoutSize(p); p.setPreferredSize(d); }
From source file:org.jfree.chart.demo.GradientPaintTransformerDemo1.java
public static JPanel createDemoPanel() { JPanel jpanel = new JPanel(new GridLayout(2, 2)); jpanel.setPreferredSize(new Dimension(800, 600)); CategoryDataset categorydataset = createDataset(); JFreeChart jfreechart = createChart("Type: VERTICAL", categorydataset); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer(); barrenderer.setDrawBarOutline(false); barrenderer.setSeriesPaint(0, new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, Color.yellow)); barrenderer.setSeriesPaint(1, new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, Color.green)); barrenderer.setGradientPaintTransformer( new StandardGradientPaintTransformer(GradientPaintTransformType.VERTICAL)); ChartPanel chartpanel = new ChartPanel(jfreechart); jpanel.add(chartpanel);/*from ww w . j a v a 2s. c om*/ JFreeChart jfreechart1 = createChart("Type: HORIZONTAL", categorydataset); CategoryPlot categoryplot1 = (CategoryPlot) jfreechart1.getPlot(); BarRenderer barrenderer1 = (BarRenderer) categoryplot1.getRenderer(); barrenderer1.setDrawBarOutline(false); barrenderer1.setSeriesPaint(0, new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, Color.yellow)); barrenderer1.setSeriesPaint(1, new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, Color.green)); barrenderer1.setGradientPaintTransformer( new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL)); ChartPanel chartpanel1 = new ChartPanel(jfreechart1); jpanel.add(chartpanel1); JFreeChart jfreechart2 = createChart("Type: CENTER_VERTICAL", categorydataset); CategoryPlot categoryplot2 = (CategoryPlot) jfreechart2.getPlot(); BarRenderer barrenderer2 = (BarRenderer) categoryplot2.getRenderer(); barrenderer2.setDrawBarOutline(false); barrenderer2.setSeriesPaint(0, new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, Color.yellow)); barrenderer2.setSeriesPaint(1, new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, Color.green)); barrenderer2.setGradientPaintTransformer( new StandardGradientPaintTransformer(GradientPaintTransformType.CENTER_VERTICAL)); ChartPanel chartpanel2 = new ChartPanel(jfreechart2); jpanel.add(chartpanel2); JFreeChart jfreechart3 = createChart("Type: CENTER_HORIZONTAL", categorydataset); CategoryPlot categoryplot3 = (CategoryPlot) jfreechart3.getPlot(); BarRenderer barrenderer3 = (BarRenderer) categoryplot3.getRenderer(); barrenderer3.setDrawBarOutline(false); barrenderer3.setSeriesPaint(0, new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, Color.yellow)); barrenderer3.setSeriesPaint(1, new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, Color.green)); barrenderer3.setGradientPaintTransformer( new StandardGradientPaintTransformer(GradientPaintTransformType.CENTER_HORIZONTAL)); ChartPanel chartpanel3 = new ChartPanel(jfreechart3); jpanel.add(chartpanel3); return jpanel; }
From source file:org.jfree.chart.demo.ClusteredXYBarRendererDemo1.java
public static JPanel createDemoPanel() { JPanel jpanel = new JPanel(new GridLayout(2, 2)); jpanel.setPreferredSize(new Dimension(800, 600)); IntervalXYDataset intervalxydataset = createDataset(); JFreeChart jfreechart = createChart("Vertical", intervalxydataset); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); XYBarRenderer xybarrenderer = (XYBarRenderer) xyplot.getRenderer(); xybarrenderer.setDrawBarOutline(false); xybarrenderer.setSeriesPaint(0, new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, Color.yellow)); xybarrenderer.setSeriesPaint(1, new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, Color.green)); xybarrenderer.setGradientPaintTransformer( new StandardGradientPaintTransformer(GradientPaintTransformType.VERTICAL)); ChartPanel chartpanel = new ChartPanel(jfreechart); jpanel.add(chartpanel);/*from w w w. jav a2 s . com*/ JFreeChart jfreechart1 = createChart("Vertical / Inverted Axis", intervalxydataset); XYPlot xyplot1 = (XYPlot) jfreechart1.getPlot(); XYBarRenderer xybarrenderer1 = (XYBarRenderer) xyplot1.getRenderer(); xybarrenderer1.setDrawBarOutline(false); xybarrenderer1.setSeriesPaint(0, new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, Color.yellow)); xybarrenderer1.setSeriesPaint(1, new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, Color.green)); xybarrenderer1.setGradientPaintTransformer( new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL)); xyplot1.getDomainAxis().setInverted(true); ChartPanel chartpanel1 = new ChartPanel(jfreechart1); jpanel.add(chartpanel1); JFreeChart jfreechart2 = createChart("Horizontal", intervalxydataset); XYPlot xyplot2 = (XYPlot) jfreechart2.getPlot(); xyplot2.setOrientation(PlotOrientation.HORIZONTAL); XYBarRenderer xybarrenderer2 = (XYBarRenderer) xyplot2.getRenderer(); xybarrenderer2.setDrawBarOutline(false); xybarrenderer2.setSeriesPaint(0, new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, Color.yellow)); xybarrenderer2.setSeriesPaint(1, new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, Color.green)); xybarrenderer2.setGradientPaintTransformer( new StandardGradientPaintTransformer(GradientPaintTransformType.CENTER_VERTICAL)); ChartPanel chartpanel2 = new ChartPanel(jfreechart2); jpanel.add(chartpanel2); JFreeChart jfreechart3 = createChart("Horizontal / Inverted Axis", intervalxydataset); XYPlot xyplot3 = (XYPlot) jfreechart3.getPlot(); xyplot3.setOrientation(PlotOrientation.HORIZONTAL); XYBarRenderer xybarrenderer3 = (XYBarRenderer) xyplot3.getRenderer(); xybarrenderer3.setDrawBarOutline(false); xybarrenderer3.setSeriesPaint(0, new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, Color.yellow)); xybarrenderer3.setSeriesPaint(1, new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, Color.green)); xybarrenderer3.setGradientPaintTransformer( new StandardGradientPaintTransformer(GradientPaintTransformType.CENTER_HORIZONTAL)); xyplot3.getDomainAxis().setInverted(true); ChartPanel chartpanel3 = new ChartPanel(jfreechart3); jpanel.add(chartpanel3); return jpanel; }
From source file:Main.java
private static JPanel getPanel() { JPanel panel = new JPanel(new BorderLayout()); panel.add(new JLabel("Top"), BorderLayout.NORTH); panel.add(new JLabel("Center"), BorderLayout.CENTER); panel.add(new JLabel("Bottom"), BorderLayout.SOUTH); panel.setPreferredSize(new Dimension(400, 300)); return panel; }
From source file:Main.java
public static JPanel getPanelFlowLayoutHorizontal(int w, int h, int type) { JPanel panel = new JPanel(); FlowLayout layout = new FlowLayout(); layout.setAlignment(type);//w ww. ja va 2 s . co m panel.setLayout(layout); panel.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT); panel.setPreferredSize(getControlDimension(w, h)); panel.setMinimumSize(getControlDimension(w, h)); return panel; }