List of usage examples for java.awt GridLayout GridLayout
public GridLayout(int rows, int cols, int hgap, int vgap)
From source file:CombinedLayoutManager.java
protected JComponent getButtonPanel() { JPanel inner = new JPanel(); inner.setLayout(new GridLayout(1, 2, 10, 0)); inner.add(new JButton("Ok")); inner.add(new JButton("Cancel")); return inner; }
From source file:Charts2D.java
public Charts2D() { super("2D Charts"); setSize(720, 280);/*from w w w . ja v a 2 s .c om*/ getContentPane().setLayout(new GridLayout(1, 3, 10, 0)); getContentPane().setBackground(Color.white); int[] xData = new int[8]; int[] yData = new int[8]; for (int i = 0; i < xData.length; i++) { xData[i] = i; yData[i] = (int) (Math.random() * 100); if (i > 0) yData[i] = (yData[i - 1] + yData[i]) / 2; } JChart2D chart = new JChart2D(JChart2D.LineChart, xData.length, xData, yData, "Line Chart"); chart.setStroke(new BasicStroke(5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER)); chart.setLineColor(new Color(0, 28, 28)); getContentPane().add(chart); chart = new JChart2D(JChart2D.ColumnChart, xData.length, xData, yData, "Column Chart"); GradientPaint gp = new GradientPaint(0, 100, Color.white, 0, 300, Color.blue, true); chart.setGradient(gp); chart.setEffectIndex(JChart2D.Gradientffect); chart.setDrawShadow(true); getContentPane().add(chart); chart = new JChart2D(JChart2D.PieChart, xData.length, xData, yData, "Pie Chart"); ImageIcon icon = new ImageIcon("largeJava2slogo.GIF"); chart.setForegroundImage(icon.getImage()); chart.setEffectIndex(JChart2D.ImageEffect); chart.setDrawShadow(true); getContentPane().add(chart); WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; addWindowListener(wndCloser); setVisible(true); }
From source file:AffineTransformApp.java
public AffineTransformApp() { super();/*from w w w.ja va2s. co m*/ Container container = getContentPane(); displayPanel = new DisplayPanel(); container.add(displayPanel); JPanel panel = new JPanel(); panel.setLayout(new GridLayout(2, 4, 5, 5)); scaleXval = new JComboBox(scaleValues); scaleXval.setSelectedItem("1.00"); scaleXval.addActionListener(new ComboBoxListener()); scaleYval = new JComboBox(scaleValues); scaleYval.setSelectedItem("1.00"); scaleYval.addActionListener(new ComboBoxListener()); shearXval = new JComboBox(shearValues); shearXval.setSelectedItem("0.00"); shearXval.addActionListener(new ComboBoxListener()); shearYval = new JComboBox(shearValues); shearYval.setSelectedItem("0.00"); shearYval.addActionListener(new ComboBoxListener()); panel.add(new JLabel("Scale X value:")); panel.add(scaleXval); panel.add(new JLabel("Scale Y value:")); panel.add(scaleYval); panel.add(new JLabel("Shear X value:")); panel.add(shearXval); panel.add(new JLabel("Shear Y value:")); panel.add(shearYval); container.add(BorderLayout.SOUTH, panel); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); setSize(displayPanel.getWidth(), displayPanel.getHeight() + 10); setVisible(true); }
From source file:Main.java
public TColor() { sliderR = getSlider(0, 255, 0, 50, 5); sliderG = getSlider(0, 255, 0, 50, 5); sliderB = getSlider(0, 255, 0, 50, 5); sliderH = getSlider(0, 10, 0, 5, 1); sliderS = getSlider(0, 10, 0, 5, 1); sliderBr = getSlider(0, 10, 0, 5, 1); sliderAlpha = getSlider(0, 255, 255, 50, 5); JPanel panel = new JPanel(); panel.setLayout(new GridLayout(6, 2, 15, 0)); panel.add(new JLabel("R-G-B Sliders (0 - 255)")); panel.add(new JLabel("H-S-B Sliders (ex-1)")); panel.add(sliderR);// w ww. j a v a2s . c o m panel.add(sliderH); panel.add(sliderG); panel.add(sliderS); panel.add(sliderB); panel.add(sliderBr); panel.add(new JLabel("Alpha Adjustment (0 - 255): ", JLabel.RIGHT)); panel.add(sliderAlpha); panel.add(new JLabel("RGB Value: ", JLabel.RIGHT)); rgbValue.setBackground(Color.white); rgbValue.setForeground(Color.black); rgbValue.setOpaque(true); panel.add(rgbValue); add(panel, BorderLayout.SOUTH); add(canvas); }
From source file:SwingSuspendResume.java
public SwingSuspendResume() { symbolTF = new JTextField(); symbolTF.setEditable(false);// ww w . j a v a 2s. co m symbolTF.setFont(new Font("Monospaced", Font.BOLD, 26)); symbolTF.setHorizontalAlignment(JTextField.CENTER); final JButton suspendB = new JButton("Suspend"); final JButton resumeB = new JButton("Resume"); suspendB.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { suspendNow(); } }); resumeB.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { resumeNow(); } }); JPanel innerStackP = new JPanel(); innerStackP.setLayout(new GridLayout(0, 1, 3, 3)); innerStackP.add(symbolTF); innerStackP.add(suspendB); innerStackP.add(resumeB); this.setLayout(new FlowLayout(FlowLayout.CENTER)); this.add(innerStackP); }
From source file:org.jfree.chart.demo.RightPanel.java
public RightPanel(int x, int y, int width, int height, String baude[], String name[]) { setBackground(new Color(176, 199, 246)); this.width = width; this.height = height; Data[0] = "8"; Data[1] = "9"; Name = name;/*from www. j a va 2 s . c om*/ Baude = baude; setLayout(new GridLayout(8, 1, 0, 0)); lblName = new JLabel("Name"); lblName.setHorizontalAlignment(SwingConstants.CENTER); lblName.setFont(new Font("Arial", 15, 16)); add(lblName); comboBox = new JComboBox(Name); comboBox.setFont(new Font("Arial", 15, 16)); add(comboBox); JLabel lblBaude = new JLabel("Baude"); lblBaude.setFont(new Font("Arial", 15, 16)); lblBaude.setHorizontalAlignment(SwingConstants.CENTER); add(lblBaude); final JComboBox comboBox_1 = new JComboBox(Baude); comboBox_1.setFont(new Font("Arial", 15, 16)); add(comboBox_1); JLabel lblDataSize = new JLabel("Data size"); lblDataSize.setHorizontalAlignment(SwingConstants.CENTER); lblDataSize.setFont(new Font("Arial", 15, 16)); add(lblDataSize); final JComboBox comboBox_2 = new JComboBox(Data); comboBox_2.setFont(new Font("Arial", 15, 16)); add(comboBox_2); JSeparator separator = new JSeparator(); add(separator); btnOpen = new JButton("Open"); btnOpen.setFont(new Font("Arial", 15, 16)); btnOpen.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { if (btnOpen.getText() == "Open") { btnOpen.setText("Close"); open = true; int baude = 9600, data = 8; try { baude = Integer.parseInt((String) comboBox_1.getSelectedItem()); data = Integer.parseInt((String) comboBox_2.getSelectedItem()); } catch (Exception e) { errors += "Enter correct Bauderate\n"; error_flag = true; } comport = new Comport((String) comboBox.getSelectedItem(), baude, data); comport.start(); } else { comport.flag = false; btnOpen.setText("Open"); open = false; comport.close(); // comport.stop(); System.out.println("Comport = " + comport.isAlive()); System.out.println("Comport life = " + comport.get_life()); } } }); add(btnOpen); setBounds(x + 50, y, width - 40, height - 20); err.setBounds(x + 50, y, 50, 50); //add(err); }
From source file:Main.java
public Main() { Calendar cal = Calendar.getInstance(); Date date = cal.getTime();//from w ww. j ava2s . c o m model.setValue(date); spinner = new JSpinner(model); spinner.addChangeListener(e -> { Date d = (Date) ((JSpinner) e.getSource()).getValue(); for (int i = 0; i < labels.length; i++) { labels[i].setText(formats[i].format(d)); } }); format = ((JSpinner.DateEditor) spinner.getEditor()).getFormat(); format.setTimeZone(TimeZone.getTimeZone(zones[0])); format.applyPattern("yyyy-MM-dd HH:mm:ss"); format.applyPattern("HH:mm:ss"); panel = new JPanel(new GridLayout(zones.length, 2, 10, 10)); for (int i = 0; i < zones.length; i++) { formats[i] = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss"); formats[i] = new SimpleDateFormat("HH:mm:ss"); formats[i].setTimeZone(TimeZone.getTimeZone(zones[i])); JLabel label = new JLabel(zones[i]); labels[i] = new JLabel(formats[i].format(date)); labels[i].setHorizontalAlignment(JLabel.RIGHT); panel.add(label); panel.add(labels[i]); } frame.setLayout(new BorderLayout(10, 10)); frame.add(spinner, BorderLayout.NORTH); frame.add(panel, BorderLayout.CENTER); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); }
From source file:BoxLayoutTest.java
public BoxLayoutTest() { setTitle("BoxLayoutTest"); setSize(300, 300);/* w ww. j a va 2 s . c o m*/ addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); horizontalBox = createBox(true, false); verticalBox = createBox(false, false); horizontalStrutsAndGlueBox = createBox(true, true); verticalStrutsAndGlueBox = createBox(false, true); JPanel panel = new JPanel(); panel.setLayout(new GridLayout(3, 1, 3, 3)); ButtonGroup directionGroup = new ButtonGroup(); horizontalButton = addRadioButton(panel, directionGroup, "Horizontal", true); verticalButton = addRadioButton(panel, directionGroup, "Vertical", false); strutsAndGlueCheckBox = addCheckBox(panel, "Struts and Glue"); Container contentPane = getContentPane(); contentPane.add(panel, "South"); contentPane.add(horizontalBox, "Center"); currentBox = horizontalBox; }
From source file:ScrollDemo2.java
public void init() { JRadioButton form[][] = new JRadioButton[12][5]; String counts[] = { "", "0-1", "2-5", "6-10", "11-100", "101+" }; String categories[] = { "Household", "Office", "Extended Family", "Company (US)", "Company (World)", "Team", "Will", "Birthday Card List", "High School", "Country", "Continent", "Planet" }; JPanel p = new JPanel(); p.setSize(600, 400);/* w w w . ja va2 s.c om*/ p.setLayout(new GridLayout(13, 6, 10, 0)); for (int row = 0; row < 13; row++) { ButtonGroup bg = new ButtonGroup(); for (int col = 0; col < 6; col++) { if (row == 0) { p.add(new JLabel(counts[col])); } else { if (col == 0) { p.add(new JLabel(categories[row - 1])); } else { form[row - 1][col - 1] = new JRadioButton(); bg.add(form[row - 1][col - 1]); p.add(form[row - 1][col - 1]); } } } } scrollpane = new JScrollPane(p); // Add in some JViewports for the column and row headers JViewport jv1 = new JViewport(); jv1.setView(new JLabel(new ImageIcon("columnlabel.gif"))); scrollpane.setColumnHeader(jv1); JViewport jv2 = new JViewport(); jv2.setView(new JLabel(new ImageIcon("rowlabel.gif"))); scrollpane.setRowHeader(jv2); // And throw in an information button JButton jb1 = new JButton(new ImageIcon("question.gif")); jb1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { JOptionPane.showMessageDialog(null, "This is an Active Corner!", "Information", JOptionPane.INFORMATION_MESSAGE); } }); scrollpane.setCorner(ScrollPaneConstants.UPPER_LEFT_CORNER, jb1); getContentPane().add(scrollpane, BorderLayout.CENTER); }
From source file:Main.java
public Main() { someComboBox.setFont(new Font("Serif", Font.BOLD, 16)); someComboBox.setEditable(true);// w w w . j av a2 s .co m someComboBox.getEditor().getEditorComponent().setBackground(Color.YELLOW); ((JTextField) someComboBox.getEditor().getEditorComponent()).setBackground(Color.YELLOW); JTextField text = ((JTextField) editableComboBox.getEditor().getEditorComponent()); text.setBackground(Color.YELLOW); JComboBox coloredArrowsCombo = editableComboBox; Component[] comp = coloredArrowsCombo.getComponents(); for (int i = 0; i < comp.length; i++) { if (comp[i] instanceof MetalComboBoxButton) { MetalComboBoxButton coloredArrowsButton = (MetalComboBoxButton) comp[i]; coloredArrowsButton.setBackground(null); break; } } non_EditableComboBox.setFont(new Font("Serif", Font.BOLD, 16)); frame = new JFrame(); frame.setLayout(new GridLayout(0, 1, 10, 10)); frame.add(someComboBox); frame.add(editableComboBox); frame.add(non_EditableComboBox); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocation(100, 100); frame.pack(); frame.setVisible(true); }