backingPanel.setSize(LAYERED_PANE_SIZE); backingPanel.setLocation(2 * GAP, 2 * GAP); backingPanel.setBackground(Color.black); for (int row = 0; row < GRID_ROWS; row++) { for (int col = 0; col < GRID_COLS; col++) { panelGrid[row][col] = new JPanel(new GridBagLayout()); backingPanel.add(panelGrid[row][col]); redLabel.setBackground(Color.red.brighter().brighter()); redLabel.setPreferredSize(LABEL_SIZE); panelGrid[4][3].add(redLabel); panelGrid[1][1].add(blueLabel); dragLabel.setLocation(x, y); add(dragLabel, JLayeredPane.DRAG_LAYER); repaint(); dragLabel.setLocation(x, y); repaint(); JFrame frame = new JFrame("DragLabelOnLayeredPane"); frame.getContentPane().add(new DragLabelOnLayeredPane()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true);
component.setSize(basePanel.getSize()); component.setLocation(0, 0); componentNew.setLocation(p2); int step = 0; if ((slideType == LEFT) || (slideType == RIGHT)) { case LEFT: { p1.x -= step; componentOld.setLocation(p1); p2.x -= step; componentNew.setLocation(p2); break; componentOld.setLocation(p1); p2.x += step; componentNew.setLocation(p2); break; componentOld.setLocation(p1); p2.y -= step; componentNew.setLocation(p2); break; componentOld.setLocation(p1); p2.y += step; componentNew.setLocation(p2); break;
public void setupUI(Frame frame) { JScrollPane sp = new JScrollPane(editor); getContentPane().add(sp); pack(); setSize(800, 600); setLocation(frame.getLocationOnScreen().x + (frame.getWidth() - getSize().width) / 2, frame.getLocationOnScreen().y + (frame.getHeight() - getSize().height) / 2); }
int deltaY = e.getYOnScreen() - screenY; setLocation(myX + deltaX, myY + deltaY); JFrame f = new JFrame("Swing Hello World"); f.add(mc); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); f.setVisible(true);
/** * Creates the pane. **/ private void createPane() { // This is for the OK, Cancel, and Apply buttons JPanel buttonPanel = getButtonPanel(); // This is for the rest JPanel panel = getModifyTab(); Container container = getContentPane(); container.setLayout(new BorderLayout()); JTabbedPane tabbedPane = new JTabbedPane(); tabbedPane.addTab(modifyActionTab_, panel); // container.add("West", new JPanel()); // container.add("East", new JPanel()); container.add("South", buttonPanel); container.add("Center", tabbedPane); setLocation(parent_.getLocation().x+parent_.getSize().width/2, parent_.getLocation().y+parent_.getSize().height/2); list_.setSelectedIndex(0); textField_.setText((String)list_.getSelectedValue()); }
public void actionPerformed(ActionEvent e) { HistoryLogPane.setLayout(new ScrollPaneLayout());//<<< history = (JPanel)HistoryLogPane.getViewport().getView();//<<< javax.swing.JScrollPane HistoryLogPane = new javax.swing.JScrollPane(); HistoryLogPane.setLayout(new ScrollPaneLayout()); // edit @kiheru HistoryLogPane.setBackground(Color.WHITE); HistoryLogPane.setBorder(BorderFactory.createEmptyBorder()); HistoryLogPane.setLocation(0, 0); HistoryLogPane.add(history); HistoryLogPane.setSize(new Dimension(history.getSize())); history.setPreferredSize(history.getSize());//and we tried: history.setPreferredSize(history.getPreferredSize()); history.revalidate();//<<< System.out.println("SIZE: " + HistoryLogPane.getSize()); HistoryLocationPanel.removeAll(); HistoryLocationPanel.add(HistoryLogPane); HistoryLocationPanel.repaint(); HistoryLogPane.repaint(); }
window = new JFrame("Foo"); window.add(layeredPane, BorderLayout.CENTER); myGraphic.setSize(layeredPane.getPreferredSize()); myGraphic.setLocation(0, 0); layeredPane.add(myGraphic, JLayeredPane.DEFAULT_LAYER); window.setVisible(true);
"dialog decoration."); p.add(l); getContentPane().add(p, BorderLayout.CENTER); p.add(b); getContentPane().add(p, BorderLayout.SOUTH); setLocation(loc); setVisible(true);
this.add(one); this.add(two); this.setSize(160, 100); this.setLocation(x, y); this.setVisible(true); this.addComponentListener(new ComponentAdapter() { JFrame f = new JFrame("JDPTest"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(this); f.pack(); f.setLocationRelativeTo(null); f.setVisible(true);
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 ); yAdjustment = parentLocation.y - e.getY(); chessPiece = (JLabel)c; chessPiece.setLocation(e.getX() + xAdjustment, e.getY() + yAdjustment); layeredPane.add(chessPiece, JLayeredPane.DRAG_LAYER); y = Math.max(y, 0); chessPiece.setLocation(x, y); frame.setDefaultCloseOperation( DISPOSE_ON_CLOSE ); frame.setResizable( false ); frame.pack(); frame.setLocationRelativeTo( null ); frame.setVisible(true);
JFrame frame = new JFrame("JInternalFrame Usage Demo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); frame.setVisible(true); jdpDesktop.add(frame); try { frame.setSelected(true); true, // maximizable true);// iconifiable setSize(300, 300); setLocation(xPosition * openFrameCount, yPosition
m.setSize(d.width, d.height); m.setLocation(cx, y); m.setLocation(cx, target.getSize().height - y - m.getSize().height); main.add(buttons, BorderLayout.CENTER); buttons.add( new JRadioButton("button " + i) ); main.add(button, BorderLayout.SOUTH); button.addActionListener( new ActionListener() JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(main); frame.setSize(300, 300); frame.setLocationRelativeTo(null); frame.setVisible(true);
add(slideContainer, BorderLayout.CENTER); SlideEg mainPanel = new SlideEg(); JFrame frame = new JFrame("SlideEg"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(mainPanel); frame.pack(); frame.setLocationByPlatform(true); frame.setVisible(true); comp.setSize(getPreferredSize()); comp.setVisible(true); comp.setLocation(getPreferredSize().width, 0); slideFromRight(comp, oldComponent); return returnResult; int x = comp.getX(); if (x <= 0) { comp.setLocation(0, 0); putLayer((JComponent) comp, JLayeredPane.DEFAULT_LAYER); if (oldComponent2 != null) { } else { x -= DELTA_X; comp.setLocation(x, 0);
JFrame frame = new JFrame("Tester Frame"); frame.setSize(400, 500); btn1.setSize(150, 50); btn1.setLocation(45, 0); btn2.setSize(150, 50); btn2.setLocation(205, 0); p.add(btn1); p.add(btn2); frame.add(p); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true);
JFrame frame = new JFrame("Tester Frame"); frame.setSize(400, 500); panel.setSize(frame.size()); panel.setLocation(0, 0); btn1.setSize(150, 50); btn1.setLocation(45, 0); btn2.setSize(150, 50); btn2.setLocation(205, 0); panel.add(btn1); panel.add(btn2); content.add(panel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true);
JFrame frame=new JFrame("EmiloLadderSnack"); JPanel panel=new JPanel(); frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE); frame.setBounds(0, 0, Toolkit.getDefaultToolkit().getScreenSize().width, Toolkit.getDefaultToolkit().getScreenSize().height); frame.add(panel); BufferedImage img=null; try lbl.setLocation(50, 50); panel.add(lbl); lbl.setLocation(50, 50); frame.setVisible(true);//put it here
import javax.swing.*; import java.awt.event.*; public class Viewer { private static JButton b1 = new JButton("Action Listener"); private static JFrame f = new JFrame(); private static JPanel p = new JPanel(); private static int location = 100; //Make a variable for location public static void main(String[]args){ f.setVisible(true); f.setSize(400,400); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); p.add(b1); f.add(p); b1.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { b1.setLocation(location,100); location += 10; //This will change where it draws next time } }); } }
JFrame frame = new JFrame(); File imageFile = new File("background.bmp"); Image i = ImageIO.read(imageFile); ImageIcon image = new ImageIcon(i); JLabel imageLabel = new JLabel(image); frame.add(imageLabel); frame.setLayout(null); imageLabel.setLocation(0, 0); imageLabel.setSize(1000, 750); imageLabel.setVisible(true); frame.setVisible(true); frame.setSize(1000, 750); frame.setDefaultCloseOperation(EXIT_ON_CLOSE); } catch (IOException e) {
topPanel.add(userText, BorderLayout.CENTER); imageButton.setLocation(455, 0); imageButton.setSize(150, 30); imageButton.setLocation(435, 0); imageButton.setSize(150, 20); topPanel.add(imageButton, BorderLayout.EAST); add(topPanel, BorderLayout.NORTH); chatWindow = new JTextArea(); setVisible(true);
import javax.swing.*; import java.awt.*; import java.awt.Graphics; public class Test extends JFrame{ private JButton by; private JButton bn; JLabel startQuestion; public Test() { JPanel p = new JPanel(); by = new JButton("Yes"); bn = new JButton("No"); startQuestion = new JLabel("Would you like to start?"); //p.setLayout(null); by.setBounds(180, 250, 70, 45); bn.setBounds(250, 250, 70, 45); startQuestion.setLocation(195, 240); p.add(by); p.add(bn); add(startQuestion); add(p); setDefaultCloseOperation(3); setSize(500, 500); setVisible(true); } public static void main(String...args) { new Test(); } }