List of usage examples for javax.swing JPanel getParent
public Container getParent()
From source file:Main.java
public static void main(String[] args) { int ROWS = 100; JPanel content = new JPanel(); content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS)); content.add(new JLabel("Thanks for helping out. Use tab to move around.")); for (int i = 0; i < ROWS; i++) { JTextField field = new JTextField("" + i); field.setName("field#" + i); content.add(field);/*from w ww .ja v a 2 s. com*/ } KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener("focusOwner", new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (!(evt.getNewValue() instanceof JComponent)) { return; } JViewport viewport = (JViewport) content.getParent(); JComponent focused = (JComponent) evt.getNewValue(); if (content.isAncestorOf(focused)) { Rectangle rect = focused.getBounds(); Rectangle r2 = viewport.getVisibleRect(); content.scrollRectToVisible( new Rectangle(rect.x, rect.y, (int) r2.getWidth(), (int) r2.getHeight())); } } }); JFrame window = new JFrame(); window.setContentPane(new JScrollPane(content)); window.setSize(200, 200); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.setVisible(true); }
From source file:nl.detoren.ijsco.ui.Mainscreen.java
public JPanel createPanelScenariosButtons() { JPanel panel = new JPanel(); panel.setBackground(Color.RED); panel.setLayout(new GridLayout(0, 2)); JButton bSchemas = new JButton("1. Bepaal mogelijkheden"); bSchemas.setPreferredSize(new Dimension(40, 40)); bSchemas.addActionListener(new ActionListener() { @Override//from w w w .java2 s . c o m public void actionPerformed(ActionEvent event) { status.groepen = null; bepaalSchemas(); schemaTabel.getSelectionModel().clearSelection(); groepenText.setText(""); panel.getParent().repaint(); } }); // panel.add(bSchemas, new ExtendedGridConstraints(0, 0)); panel.add(bSchemas); JButton bGroepen = new JButton("2. Bepaal groepen"); bGroepen.setPreferredSize(new Dimension(40, 40)); bGroepen.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { if (schemaTabel != null) { List<Integer> nobyeslist; int row = schemaTabel.getSelectedRow(); nobyeslist = IJSCOController.c().nobyes; bepaalGroepen(row, Utils.toMask(nobyeslist)); new ExcelExport().exportGroepen(status.groepen); } panel.getParent().repaint(); } }); //panel.add(bGroepen, new ExtendedGridConstraints(1, 1)); panel.add(bGroepen); return panel; }
From source file:nl.detoren.ijsco.ui.Mainscreen.java
public JPanel createPanelScenarios() { JPanel panel = new JPanel(); panel.setBackground(Color.RED); panel.setLayout(new GridLayout(1, 0)); schemaModel = new SchemaModel(panel, status.schemas); schemaTabel = new JTable(schemaModel) { @Override//from ww w. ja va 2 s . co m public Component prepareRenderer(TableCellRenderer renderer, int row, int column) { Component c = super.prepareRenderer(renderer, row, column); // Tooltip if (c instanceof JComponent) { SchemaModel model = (SchemaModel) getModel(); ((JComponent) c).setToolTipText(model.getToolTip(row, column).toString()); } // Alternate row color if (!isRowSelected(row)) { c.setBackground(row % 2 == 0 ? Color.WHITE : Color.LIGHT_GRAY); } return c; } }; schemaTabel.getModel().addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent arg0) { panel.getParent().getParent().repaint(); } }); JScrollPane scrollpane = new JScrollPane(); scrollpane.setViewportView(schemaTabel); //panel.add(scrollpane, new ExtendedGridConstraints(0, 2)); panel.add(scrollpane); return panel; }
From source file:org.ut.biolab.medsavant.client.view.component.KeyValuePairPanel.java
public void setValue(String key, JComponent value) { JPanel p = keyValueComponentMap.get(key); p.removeAll();//from w ww. jav a 2s .c o m p.add(value); p.add(Box.createHorizontalGlue()); p.repaint(); p.getParent().repaint(); }