return getPreferredSize().width < getParent().getWidth(); getContentPane().add( scrollPane ); frame.setDefaultCloseOperation( EXIT_ON_CLOSE ); frame.pack(); frame.setSize(400, 300); frame.setVisible(true);
@Override public void actionPerformed(ActionEvent e) { Component p = ClassHierarchyPanel.this; while (p != null){ if (p instanceof TopComponent) { ((TopComponent)p).close(); return; } else if (p instanceof Window) { ((Window)p).setVisible(false); return; } p = p.getParent(); } } }
JFrame frame = new JFrame(); JPanel panel = new JPanel(); JLabel label = new JLabel("Loading..."); JProgressBar jpb = new JProgressBar(); jpb.setIndeterminate(true); panel.add(label); panel.add(jpb); frame.add(panel); frame.pack(); frame.setSize(200,90); frame.setLocationRelativeTo(null); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); new Task_StringUpdate(label).execute(); try { get(); JOptionPane.showMessageDialog(jlabel.getParent(), "Success", "Success", JOptionPane.INFORMATION_MESSAGE); } catch (ExecutionException | InterruptedException e) { e.printStackTrace();
@Override public void actionPerformed(ActionEvent e) { Component p = IncludeHierarchyPanel.this; while (p != null){ if (p instanceof TopComponent) { ((TopComponent)p).close(); return; } else if (p instanceof Window) { ((Window)p).setVisible(false); return; } p = p.getParent(); } } }
JFrame frame = new JFrame(); JPanel panel = new JPanel(); JLabel label = new JLabel("Loading..."); int max = 1000; jpb.setMaximum(max); panel.add(label); panel.add(jpb); frame.add(panel); frame.pack(); frame.setSize(200,90); frame.setLocationRelativeTo(null); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); new Task_IntegerUpdate(jpb, max, label).execute(); try { get(); JOptionPane.showMessageDialog(jpb.getParent(), "Success", "Success", JOptionPane.INFORMATION_MESSAGE); } catch (ExecutionException | InterruptedException e) { e.printStackTrace();
/** * Returns the <code>ComponentInfo</code> for the specified Component. */ private ComponentInfo getComponentInfo(Component component) { ComponentInfo info = (ComponentInfo)componentInfos.get(component); if (info == null) { info = new ComponentInfo(component); componentInfos.put(component, info); if (component.getParent() != host) { host.add(component); } } return info; }
public void actionPerformed(ActionEvent e) { Component src = (Component)e.getSource(); Container parent = src.getParent(); while(parent!=null) { if( parent instanceof JInternalFrame ) { ((JInternalFrame)parent).setVisible(false); ((JInternalFrame)parent).dispose(); return; } else if(parent instanceof Window) { ((Window)parent).setVisible(false); ((Window)parent).dispose(); return; } parent = parent.getParent(); } } };
public boolean getScrollableTracksViewportWidth() return getPreferredSize().width < getParent().getWidth(); if (tcm.getTotalColumnWidth() < getParent().getWidth()) setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); super.doLayout(); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new JScrollPane(table)); frame.pack(); frame.setVisible(true);
getContentPane().add( new JScrollPane(table) ); JPopupMenu popup = (JPopupMenu)c.getParent(); JTable table = (JTable)popup.getInvoker(); System.out.println(table.getSelectedRow() + " : " + table.getSelectedColumn()); frame.setDefaultCloseOperation( EXIT_ON_CLOSE ); frame.pack(); frame.setLocationRelativeTo( null ); frame.setVisible( true );
import javax.swing.*; import java.applet.Applet; import java.awt.*; public class Tetris extends Applet { public void init() { Frame title = (Frame)this.getParent().getParent(); title.setTitle("New Title"); setSize(250, 500); JPanel grid = new JPanel(); grid.setSize(250,500); add(grid, BorderLayout. CENTER); } }
layeredPane.addMouseListener( this ); layeredPane.addMouseMotionListener( this ); getContentPane().add(layeredPane); chessBoard.setPreferredSize( boardSize ); chessBoard.setBounds(0, 0, boardSize.width, boardSize.height); layeredPane.add(chessBoard, JLayeredPane.DEFAULT_LAYER); chessBoard.add( square ); Point parentLocation = c.getParent().getLocation(); xAdjustment = parentLocation.x - e.getX(); yAdjustment = parentLocation.y - e.getY(); Container parent = c.getParent(); parent.remove(0); parent.add( chessPiece ); frame.setDefaultCloseOperation( DISPOSE_ON_CLOSE ); frame.setResizable( false ); frame.pack(); frame.setLocationRelativeTo( null ); frame.setVisible(true);
/** * Maximises the given component, to occupy the whole container. * <p> * The maximisation is done by adding the component directly to the container. If another component is already maximised it * does nothing. * * @param component the component to maximise * @throws IllegalArgumentException if the given {@code component} is {@code null}. * @see #unmaximiseComponent() * @see #isComponentMaximised() */ public void maximiseComponent(Component component) { if (component == null) { throw new IllegalArgumentException("Parameter component must not be null."); } if (maximisedComponent != null) { return; } maximisedComponent = component; parentMaximisedComponent = component.getParent(); containerChild = container.getComponent(0); parentMaximisedComponent.remove(component); container.remove(containerChild); container.add(component); container.validate(); }
frame.addInternalFrameListener(InternalWindowListener.wrap(listener)); ((JDesktopPane) owner).add(frame); frame.getContentPane().add(panel); frame.pack(); return frame; dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.addWindowListener(listener); dialog.getContentPane().add(panel); dialog.pack(); return dialog; dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.addWindowListener(listener); dialog.getContentPane().add(panel); dialog.pack(); return dialog; owner = owner.getParent(); final JFrame frame = new JFrame(title); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.addWindowListener(listener); frame.getContentPane().add(panel);
public void actionPerformed(ActionEvent evt) { JButton src = (JButton) evt.getSource(); JPanel container = (JPanel) src.getParent(); container.remove(src); container.revalidate(); for (int i = 0; i < BUTTON_COUNT; i++) { JButton removeBtn = new JButton(removeAction); btnPanel.add(removeBtn); borderPanel.add(btnPanel, BorderLayout.NORTH); JScrollPane scrollpane = new JScrollPane(borderPanel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, scrollpane.setPreferredSize(new Dimension(400, 800)); JFrame frame = new JFrame("Foo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(scrollpane); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true);
class ButtonClickActionK implements ActionListener { public void actionPerformed(ActionEvent e) { String str = e.getActionCommand(); Component source = (Component) e.getSource(); switch (str) { case "TextButton": Container parent = source.getParent(); JXCollapsiblePane testp = new JXCollapsiblePane(); testp.add(new JLabel("dummy, just to see we are open")); parent.add(testp); parent.revalidate(); break; default: JOptionPane.showMessageDialog(source, "Erm, this is embarrasing! Something went (horribly) wrong..."); } } } // usage JButton newButton= new JButton("TextButton"); newButton.addActionListener(new ButtonClickActionK()); // note: _not_ using a class field JComponent newPanel = new JPanel(new VerticalLayout()); newPanel.add(newButton);
JPanel square = new SquarePanel(); square.setBackground(Color.RED); gui.add(square); JFrame f = new JFrame("SquareBoard"); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); f.setLocationByPlatform(true); f.add(gui); f.setMinimumSize(new Dimension(400,100)); f.pack(); f.setVisible(true); @Override public Dimension getPreferredSize() { Container c = this.getParent(); int size = Math.min(c.getHeight(), c.getWidth()); Dimension d = new Dimension(size,size);