List of usage examples for javax.swing JFrame setContentPane
@BeanProperty(bound = false, hidden = true, description = "The client area of the frame where child components are normally inserted.") public void setContentPane(Container contentPane)
contentPane
property. From source file:Main.java
public static void main(String[] args) { JTextPane pane = new JTextPane(); TabStop[] tabs = new TabStop[2]; tabs[0] = new TabStop(60, TabStop.ALIGN_RIGHT, TabStop.LEAD_NONE); tabs[1] = new TabStop(100, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE); TabSet tabset = new TabSet(tabs); StyleContext sc = StyleContext.getDefaultStyleContext(); AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.TabSet, tabset); pane.setParagraphAttributes(aset, false); pane.setText("\tright\tleft\tcenter\tValue\n" + "\t200.002\t200.002\t200.002\t200.002\n"); JFrame d = new JFrame(); d.setContentPane(new JScrollPane(pane)); d.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); d.setSize(360, 120);/*from ww w . j a v a2 s . co m*/ d.setVisible(true); }
From source file:SwingHtmlLabel.java
public static void main(String argv[]) { JPanel p = new JPanel(new java.awt.GridLayout(0, 1)); p.add(new JLabel(markup)); p.add(new java.awt.Label(markup)); JFrame f = new JFrame("SwingHtmlLabel"); f.setContentPane(p); f.setSize(600, 200);/* ww w. ja va 2 s.c o m*/ f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JTabbedPane tabbedPane = new JTabbedPane(); tabbedPane.setUI(new MetalTabbedPaneUI() { @Override/*from ww w. j av a 2s .c o m*/ protected int calculateTabWidth(int tabPlacement, int tabIndex, FontMetrics metrics) { int width = super.calculateTabWidth(tabPlacement, tabIndex, metrics); int extra = tabIndex * 50; return width + extra; } }); tabbedPane.addTab("JTable", new JScrollPane(new JTable(5, 5))); tabbedPane.addTab("JTree", new JScrollPane(new JTree())); tabbedPane.addTab("JSplitPane", new JSplitPane()); JPanel p = new JPanel(); p.add(tabbedPane); JFrame frame = new JFrame(); frame.setContentPane(p); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JTextPane pane = new JTextPane(); TabStop[] tabs = new TabStop[1]; tabs[0] = new TabStop(60, TabStop.ALIGN_RIGHT, TabStop.LEAD_NONE); TabSet tabset = new TabSet(tabs); StyleContext sc = StyleContext.getDefaultStyleContext(); AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.TabSet, tabset); pane.setParagraphAttributes(aset, false); pane.setText("\tright\tleft\tcenter\tdecimal\n" + "\t1\t1\t1\t1.0\n" + "\t200.002\t200.002\t200.002\t200.002\n" + "\t.33\t.33\t.33\t.33\n"); JFrame frame = new JFrame("TabExample"); frame.setContentPane(new JScrollPane(pane)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(360, 120);/*from ww w.j a v a 2s.co m*/ frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws Exception { Object[][] data = { { "A", new Integer(3), new Double(7.23), new Boolean(true) }, { "J", new Integer(2), new Double(4.64), new Boolean(false) }, { "S", new Integer(1), new Double(8.81), new Boolean(true) } }; String[] columns = { "Col", "Col", "Col", "Col" }; JTable table = new JTable(data, columns); JScrollPane scroll = new JScrollPane(table); JFrame f = new JFrame(); f.setContentPane(scroll); f.pack();/*www.ja va 2s . c o m*/ int x = (int) table.getTableHeader().getSize().getWidth(); int y = (int) table.getTableHeader().getSize().getHeight() + (int) table.getSize().getHeight(); BufferedImage bi = new BufferedImage((int) x, (int) y, BufferedImage.TYPE_INT_RGB); Graphics g = bi.createGraphics(); table.getTableHeader().paint(g); g.translate(0, table.getTableHeader().getHeight()); table.paint(g); g.dispose(); JOptionPane.showMessageDialog(null, new JLabel(new ImageIcon(bi))); ImageIO.write(bi, "png", new File("c:/Java_Dev/table.png")); System.exit(0); }
From source file:MaxLengthDocument.java
public static void main(String[] args) { Document doc = new MaxLengthDocument(5); JTextField field = new JTextField(doc, "", 8); JPanel flowPanel = new JPanel(); flowPanel.add(field);/*from www .ja va2 s .c om*/ JFrame frame = new JFrame("MaxLengthDocument demo"); frame.setContentPane(flowPanel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(160, 80); frame.setVisible(true); }
From source file:MaxLengthDocument.java
public static void main(String[] a) { Document doc = new MaxLengthDocument(5); // set maximum length to 5 JTextField field = new JTextField(doc, "", 8); JPanel flowPanel = new JPanel(); flowPanel.add(field);/*from w ww . j a va 2 s. c o m*/ JFrame frame = new JFrame("MaxLengthDocument demo"); frame.setContentPane(flowPanel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(160, 80); frame.setVisible(true); }
From source file:TabExample.java
public static void main(String[] args) { JTextPane pane = new JTextPane(); TabStop[] tabs = new TabStop[4]; tabs[0] = new TabStop(60, TabStop.ALIGN_RIGHT, TabStop.LEAD_NONE); tabs[1] = new TabStop(100, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE); tabs[2] = new TabStop(200, TabStop.ALIGN_CENTER, TabStop.LEAD_NONE); tabs[3] = new TabStop(300, TabStop.ALIGN_DECIMAL, TabStop.LEAD_NONE); TabSet tabset = new TabSet(tabs); StyleContext sc = StyleContext.getDefaultStyleContext(); AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.TabSet, tabset); pane.setParagraphAttributes(aset, false); pane.setText("\tright\tleft\tcenter\tdecimal\n" + "\t1\t1\t1\t1.0\n" + "\t200.002\t200.002\t200.002\t200.002\n" + "\t.33\t.33\t.33\t.33\n"); JFrame frame = new JFrame("TabExample"); frame.setContentPane(new JScrollPane(pane)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(360, 120);//from w ww. j a v a 2 s. co m frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setContentPane(new StringPanel()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack();/*from ww w. j a v a 2 s . c om*/ frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JTextField[] txtAllAverages;/*from w ww. j av a2 s . co m*/ int testCount = 2; txtAllAverages = new JTextField[testCount]; JPanel inputControls = new JPanel(new BorderLayout(5, 5)); JPanel inputControlsLabels = new JPanel(new GridLayout(0, 1, 3, 3)); JPanel inputControlsFields = new JPanel(new GridLayout(0, 1, 3, 3)); inputControls.add(inputControlsLabels, BorderLayout.WEST); inputControls.add(inputControlsFields, BorderLayout.CENTER); for (int i = 0; i < testCount; i++) { inputControlsLabels.add(new JLabel("Test score: ")); JTextField field = new JTextField(10); inputControlsFields.add(field); txtAllAverages[i] = field; } JPanel controls = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 2)); controls.add(new JButton("Reset")); controls.add(new JButton("Submit")); JPanel gui = new JPanel(new BorderLayout(10, 10)); gui.setBorder(new TitledBorder("Averages")); gui.add(inputControls, BorderLayout.CENTER); gui.add(controls, BorderLayout.SOUTH); JFrame f = new JFrame(); f.setContentPane(gui); f.pack(); f.setLocationByPlatform(true); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }