import javax.swing.*; import java.awt.*; public class Main { public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); frame.setSize(600, 400); JPanel panel = new JPanel() { @Override public void paintComponent(Graphics g) { super.paintComponent(g); g.setColor(Color.BLUE); g.fillRect(0, 0, 100, 100); } }; frame.add(panel); // Graphics g = panel.getGraphics(); // g.setColor(Color.BLUE); // g.fillRect(0, 0, 100, 100); frame.validate(); // because you added panel after setVisible was called frame.repaint(); // because you added panel after setVisible was called } }
JPanel p = new JPanel(); mediaTypes.createGui(p, show); add(p); validate(); MediaTypes mediaTypes = new MediaTypes(); JPanel p = new JPanel(); mediaTypes.createGui(p); JOptionPane.showMessageDialog(null,p); panel.add(output, BorderLayout.SOUTH); d = new Dimension(450,d.height); tableScroll.setPreferredSize(d); panel.add( tableScroll, BorderLayout.CENTER );
frame.getContentPane().add(button); frame.pack(); frame.setVisible(true); progressBar.setStringPainted(true); progressBar.setIndeterminate(true); dialog.getContentPane().add(progressBar); dialog.pack(); dialog.setModal( false ); JLabel label = new JLabel("Task Complete"); dialog.getContentPane().remove(progressBar); dialog.getContentPane().add(label); dialog.getContentPane().validate();
setDefaultCloseOperation(EXIT_ON_CLOSE); setUndecorated(isFullScreen); setResizable(!isFullScreen); validate(); } else { this.setVisible(true);
import javax.swing.*; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; public class Test { public Test() { final JFrame frame = new JFrame("Screen Saver"); frame.validate(); frame.setVisible(true); KeyAdapter listener = new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { frame.dispose(); } }; frame.addKeyListener(listener); } public static void main(String[] args) { new Test(); } }
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); frame.setSize(600, 400); frame.add(panel); frame.validate(); // because you added panel after setVisible was called
private static final int TOP = 0x03; private static final int BOTTOM = 0x04; private final JPanel basePanel = new JPanel(); private final ParentType parent; private final Object lock = new Object(); glassPane = new JPanel(); glassPane.setOpaque(false); glassPane.addMouseListener(new MouseAdapter() { basePanel.setLayout(new BorderLayout()); if (useSlideButton) { final JPanel statusPanel = new JPanel(); basePanel.add(statusPanel, BorderLayout.SOUTH); statusPanel.add(new JButton("Slide Left") { private static final long serialVersionUID = 9204819004142223529L; statusPanel.add(new JButton("Slide Right") { ((JFrame) parent).getContentPane().setBackground(jPanels.get(0).getBackground()); parent.remove(basePanel); parent.validate(); parent.validate(); parent.validate();
Component c = f.getComponents()[0]; f.remove(c); f.setVisible(false); add(c); validate();
this.device = device; setTitle("Display Mode Test"); setDefaultCloseOperation(EXIT_ON_CLOSE); validate(); } else { setVisible(true);
void mouseRelease(MouseEvent e){ if(alreadyDrawn){ if(SplitterLayout.dragee!=this) return; SplitterLayout.dragee = null; Point p = wBar.getLocationOnScreen(); SwingUtilities.convertPointFromScreen(p, getParent()); wBar.setVisible(false); wBar.dispose(); wBar = null; alreadyDrawn = false; Rectangle r = getBounds(); // mouse event is relative to this... r.x += e.getX(); // //System.out.println("mouseReleased converted point "+ p); // //System.out.println("mouseRelease bounds of this spliltter " + r); setLocation(p.x, r.y); setCursor(DEF_CURSOR); // check to see if we need to move other splitters and hide other // components that are controlled by the layout // First -- find what component this one is checkOtherComponents(); mouseInside = false; invalidate(); getParent().validate(); SplitterLayout.dragee = null; } }
super("Add component on JFrame at runtime"); setLayout(new BorderLayout()); this.panel = new JPanel(); this.panel.setLayout(new FlowLayout()); add(panel, BorderLayout.CENTER); JButton button = new JButton("CLICK HERE"); add(button, BorderLayout.SOUTH); button.addActionListener(this); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(500, 500); setVisible(true); this.panel.add(new JButton("Button")); this.panel.revalidate(); validate();
private void createErrorPanel() { container.removeAll(); JPanel panel = new JPanel(new BorderLayout()); panel.add(createErrorPane(), BorderLayout.NORTH); panel.add(createVisualizationPane(), BorderLayout.CENTER); container.add(panel, BorderLayout.CENTER); container.add(createControlPane(), BorderLayout.SOUTH); container.validate(); }
private void moveToStep(final Step newStep) { remove(panelForCurrentStep()); currentStep = newStep; if (currentStep.isAllowCommit()) { commitButton.setText(CheckStyleBundle.message("config.file.okay.text")); commitButton.setToolTipText(CheckStyleBundle.message("config.file.okay.text")); } else { commitButton.setText(CheckStyleBundle.message("config.file.next.text")); commitButton.setToolTipText(CheckStyleBundle.message("config.file.next.text")); } previousButton.setEnabled(currentStep.isAllowPrevious()); commitButton.setEnabled(currentStep.isAllowNext() || currentStep.isAllowCommit()); getContentPane().add(panelForCurrentStep(), BorderLayout.CENTER); getContentPane().validate(); getContentPane().repaint(); }
((Window) floatingToolBar).setVisible(false); UIManager.removePropertyChangeListener(propertyListener); dockingSource.add(toolBar, constraint.intValue()); dockingSource.invalidate(); Container dockingSourceParent = dockingSource.getParent(); if (dockingSourceParent != null) { dockingSourceParent.validate();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JPanel gui = new JPanel(new BorderLayout(5,5)); gui.setBorder( new TitledBorder("BorderLayout(5,5)") ); JPanel plafComponents = new JPanel( new FlowLayout(FlowLayout.RIGHT, 3,3)); plafComponents.setBorder( plafComponents.add(plafChooser); plafComponents.add(pack); gui.add(plafComponents, BorderLayout.NORTH); JPanel dynamicLabels = new JPanel(new BorderLayout(4,4)); dynamicLabels.setBorder( new TitledBorder("BorderLayout(4,4)") ); labels.add( new JLabel("Label " + ++labelCount) ); frame.validate(); frame.setVisible(true);
//<applet code='Apletas' width='600' height='400'></applet> import java.awt.BorderLayout; import javax.swing.*; import javax.swing.border.EmptyBorder; public class Apletas extends JApplet { private JTextField inputLine; public Apletas() { inputLine = new JTextField(20); JPanel mainGui = new JPanel(new BorderLayout(20,20)); mainGui.setBorder(new EmptyBorder(80,80,80,80)); mainGui.add(inputLine, BorderLayout.NORTH); mainGui.add(new JScrollPane(new JTextArea(20,10)), BorderLayout.CENTER); JTree tree = new JTree(); tree.expandRow(2); mainGui.add(new JScrollPane(tree), BorderLayout.WEST); setContentPane(mainGui); validate(); } }
public void close() { Container parent = getParent(); if (!(parent instanceof JSplitPane)) return; JSplitPane split = (JSplitPane) parent; Component firstComponent = split.getTopComponent(); Component secondComponent = split.getBottomComponent(); Component remainingComponent = firstComponent == this ? secondComponent : firstComponent; split.setTopComponent(null); split.setBottomComponent(null); Container grandParent = parent.getParent(); if (grandParent instanceof JSplitPane) { JSplitPane grandSplit = (JSplitPane) grandParent; // Remove the split pane. if (split == grandSplit.getTopComponent()) { grandSplit.setTopComponent(remainingComponent); } else { grandSplit.setBottomComponent(remainingComponent); } } else { grandParent.remove(parent); grandParent.add(remainingComponent); } grandParent.validate(); }
public void windowClosing(WindowEvent w) { if (toolBar.isFloatable() == true) { if (dragWindow != null) dragWindow.setVisible(false); floating= false; if (floatingToolBar == null) floatingToolBar= createFloatingWindow(toolBar); if (floatingToolBar instanceof Window) ((Window) floatingToolBar).setVisible(false); floatingToolBar.getContentPane().remove(toolBar); String constraint= constraintBeforeFloating; int orientation= mapConstraintToOrientation(constraint); setOrientation(orientation); if (dockingSource == null) dockingSource= toolBar.getParent(); if (propertyListener != null) UIManager.removePropertyChangeListener(propertyListener); dockingSource.add(constraint, toolBar); dockingSource.invalidate(); Container dockingSourceParent= dockingSource.getParent(); if (dockingSourceParent != null) dockingSourceParent.validate(); dockingSource.repaint(); setFloating(false, null); } }