panelWidth = x + taskButton.getWidth(); taskButton.setLocation(x, y); add(taskButton);
@Override public void doLayout() { // Position transform and show source buttons buttonPanel.setLocation(cardXOffset, cardYOffset); buttonPanel.setSize(cardWidth, cardHeight); int x = cardWidth / 20; int y = cardHeight / 10; if (dayNightButton != null) { dayNightButton.setLocation(x, y); y += 25; y += 5; } if (showCopySourceButton != null) { showCopySourceButton.setLocation(x, y); } }
private void setTypeIcon(BufferedImage bufferedImage, String toolTipText) { iconPanel = new JPanel(); iconPanel.setLayout(null); iconPanel.setOpaque(false); add(iconPanel); typeButton = new JButton(""); typeButton.setLocation(2, 2); typeButton.setSize(25, 25); iconPanel.setVisible(true); typeButton.setIcon(new ImageIcon(bufferedImage)); if (toolTipText != null) { typeButton.setToolTipText(toolTipText); } iconPanel.add(typeButton); }
public MageFloatPane() { UI.setHTMLEditorKit(this); setEditable(false); setBackground(Color.white); JButton jb = new JButton("Done"); jb.setLocation(50, 50); jb.setSize(100, 50); add(jb); }
private Random d = new Random(); private JButton button = new JButton("Button"); button.addMouseListener(new MouseAdapter(){ @Override public void mouseEntered(MouseEvent e) { int a = d.nextInt(200); int b = d.nextInt(200); button.setLocation(a, b); } });
private void initResetDefaultsButton() { JButton defaultsButton = initButton("Reset Default Colors (D)", SMALL_BUTTON_SIZE, 1); defaultsButton.setLocation(0, 0); resetToDefaultAction = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { setDefaultColors(); } }; defaultsButton.addActionListener(resetToDefaultAction); }
public void createButton(int x, int y, String s) { try { JButton btn1 = new JButton(s); jPanel1.add(btn1); btn1.setLocation(x, y); btn1.setSize(50, 50); btn1.setVisible(true); } catch (Exception e) { e.printStackTrace(); System.out.println(e); } }
public static JButton button(String name, int size1, int size2, int loc1, int loc2) { JButton l=new JButton(name); l.setSize(size1, size2); l.setLocation(loc1, loc2); return l; }
public static JButton button(String name, int size1, int size2, int loc1, int loc2) { JButton button = new JButton(name); button.setSize(size1, size2); button.setLocation(loc1, loc2); return button; }
JFrame frame = new JFrame(); JPanel menuPanel = new JPanel(); JButton Button1 = new JButton("<BUTTON NAME 1>"); Button1.setSize(80, 30); Button1.setLocation(4, 4); JButton Button2 = new JButton("<BUTTON NAME 2>"); Button2.setSize(80, 30); Button2.setLocation(90, 4);
private void initSwapColorsButton() { JButton swapButton = initButton("Swap Colors (X)", SMALL_BUTTON_SIZE, 1); swapButton.setLocation(SMALL_BUTTON_SIZE, 0); swapColorsAction = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { swapColors(); } }; swapButton.addActionListener(swapColorsAction); }
public class Testing { public static void main(String[] args) { JFrame frame = new JFrame("hi"); for (int i = 0; i < 10; i++) { JButton a = new JButton(); a.setSize(20,20); a.setLocation(20*i, 0); frame.getContentPane().add(a); } frame.setLayout(null); frame.pack(); frame.setVisible(true); } }
JButton scoreButton =new JButton("add"); scoreButton.setSize(100, 50); scoreButton.setLocation(100,50); scoreButton.setBackground(Color.red); scoreButton.addActionListener(this); MyPanel.add(scoreButton);
int buttonHeight = 10; int buttonWidth = 10; for (int i = 0; i < 10; i++) { JButton button = new Button("Button " + i); button.setSize(buttonWidth, buttonHeight); button.setLocation(10 + i * buttonWidth, 10); getContentPane().add(button); }
JButton j=new JButton("START"); j.setSize(100,50); j.setLocation(imageLabel.getWidth()/2-j.getWidth()/2, imageLabel.getHeight()/2-j.getHeight()/2); //then add Button into imageLabel imageLabel.add(j);
private void initFGButton() { fgButton = initButton("Set Foreground Color", BIG_BUTTON_SIZE, 2); fgButton.addActionListener(e -> fgButtonPressed()); fgButton.setLocation(0, SMALL_BUTTON_VERTICAL_SPACE); fgButton.setComponentPopupMenu(createPopupMenu(true)); }
private void initBGButton() { bgButton = initButton("Set Background Color", BIG_BUTTON_SIZE, 1); bgButton.addActionListener(e -> bgButtonPressed()); bgButton.setLocation(BIG_BUTTON_SIZE / 2, SMALL_BUTTON_VERTICAL_SPACE + BIG_BUTTON_SIZE / 2); bgButton.setComponentPopupMenu(createPopupMenu(false)); }
private void initButton(String name, int y, Class<? extends Action> actionClass) { ImageIcon icon = ModelerUtil.buildIcon("welcome/welcome-screen-"+name+"-btn.png"); ImageIcon hoverIcon = ModelerUtil.buildIcon("welcome/welcome-screen-"+name+"-btn-hover.png"); JButton button = createButton(icon, hoverIcon); button.setLocation(24, y); // 24px - button left & right padding button.addActionListener(Application .getInstance() .getActionManager() .getAction(actionClass)); buttonsPanel.add(button); }
@ScriptFunction @Override public void setLeft(int aValue) { if (super.getParent() != null && super.getParent().getLayout() instanceof MarginLayout) { MarginLayout.ajustLeft(this, aValue); } super.setLocation(aValue, getTop()); }
@ScriptFunction @Override public void setTop(int aValue) { if (super.getParent() != null && super.getParent().getLayout() instanceof MarginLayout) { MarginLayout.ajustTop(this, aValue); } super.setLocation(getLeft(), aValue); }