try { JPanel menuPanel = new JPanel(); BufferedImage img = ImageIO.read(this.getClass().getResource("background2.png")); JLabel menuLabel = new JLabel(new ImageIcon(img)); menuLabel.setSize(800, 540); menuLabel.setLocation(0, 0); menuLabel.setVisible(true); menuPanel.add(menuLabel); this.add(menuPanel); //This might not work, try the name of the JFrame instance menuPanel.grabFocus(); menuPanel.requestFocusInWindow(); this.revalidate() //Use the name of the JFrame if this is not a JFrame or if this.add(menuPanel); doesnt work } catch (IOException e) { e.printStackTrace(); }
/** * * @param panel * @param title * @throws HeadlessException */ private static void addPanelToDialog(final JDialog dialog, final JPanel panel, final String title) throws HeadlessException { // panel.setBorder(createTitledBorder(title)); dialog.add(new JKScrollPane(panel)); panel.setOpaque(true); dialog.applyComponentOrientation(getDefaultComponentOrientation()); panel.grabFocus(); }
/** * Updates the style of the given button to indicate that it is * selected. */ protected void select(JToggleButton b) { b.setOpaque(true); b.setBackground (Platform.isOSX ? new Color(0xd8, 0xd8, 0xd8) : UIManager.getColor("List.selectionBackground")); b.setForeground(UIManager.getColor("List.selectionForeground")); b.setBorder(BorderFactory.createCompoundBorder (BorderFactory.createMatteBorder (0, 1, 0, 1, new Color(160, 160, 160)), BorderFactory.createEmptyBorder(4, 3, 4, 3))); layout.show(panel, b.getText().intern()); page = getComponentIndex(b) - 1; if (Platform.isOSX) { PreferenceDialog.this.setTitle(b.getText()); } PreferenceDialog.this.pack(); panel.grabFocus(); }
/** * Updates the style of the given button to indicate that it is * selected. */ protected void select(JToggleButton b) { b.setOpaque(true); b.setBackground (Platform.isOSX ? new Color(0xd8, 0xd8, 0xd8) : UIManager.getColor("List.selectionBackground")); b.setForeground(UIManager.getColor("List.selectionForeground")); b.setBorder(BorderFactory.createCompoundBorder (BorderFactory.createMatteBorder (0, 1, 0, 1, new Color(160, 160, 160)), BorderFactory.createEmptyBorder(4, 3, 4, 3))); layout.show(panel, b.getText().intern()); page = getComponentIndex(b) - 1; if (Platform.isOSX) { PreferenceDialog.this.setTitle(b.getText()); } PreferenceDialog.this.pack(); panel.grabFocus(); }