javax.swing.JPanel#setSize ( )源码实例Demo

下面列出了javax.swing.JPanel#setSize ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: jdk8u_jdk   文件: ThemeReaderCrashTest.java
ThemeReaderCrashTest() {
    JPanel panel = new JPanel();
    JScrollPane pane =
        new JScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
                        ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
    panel.setSize(300, 200);

    panel.add(pane);
}
 
private static JPanel createPanel(Point location, boolean enabled) {
    final JPanel panel = new JPanel();
    panel.setOpaque(false);
    panel.setEnabled(enabled);
    panel.setSize(new Dimension(200, 200));
    panel.setLocation(location);
    panel.setBorder(BorderFactory.createTitledBorder(
            enabled ? "Enabled" : "Disabled"));
    panel.setCursor(Cursor.getPredefinedCursor(
            enabled ? Cursor.CROSSHAIR_CURSOR : Cursor.DEFAULT_CURSOR));
    System.out.println("cursor: " + Cursor.getPredefinedCursor(enabled ? Cursor.CROSSHAIR_CURSOR : Cursor.DEFAULT_CURSOR));
    return panel;
}
 
源代码3 项目: ET_Redux   文件: OpenSystemModelsManager.java
private void initModels() {
    setSize(375, openModels.size() * 265 + 50);
    setTitle("Manage Plots Seawater/Open Sys Isochrons");
    setAlwaysOnTop(true);

    JPanel modelsPanel = new JPanel(null);
    modelsPanel.setSize(300, openModels.size() * 250);
    modelsPanel.setBackground(new Color(249, 237, 189));
    modelsPanel.setPreferredSize(new Dimension(300, openModels.size() * 265 + 25));
    
    int count = 0;
    for (OpenSystemIsochronTableModel osm : openModels) {
        JPanel openPanel = new OpenSystemModelDataView(osm);
        openPanel.setBounds(10, count * 245 + 10, 300, 235);
        modelsPanel.add(openPanel);
        count++;
    }
    
    JButton okButton =  new ET_JButton("OK");
    okButton.setBounds(15, count * 245 + 10, 290, 25);
    okButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            dispose();
        }
    });
    modelsPanel.add(okButton);

    JScrollPane modelsScroll = new JScrollPane(modelsPanel);
    modelsScroll.setSize(300, openModels.size() * 265);
    
    setContentPane(modelsScroll);
}
 
源代码4 项目: chipster   文件: SplashScreen.java
public SplashScreen(Icon icon) {
	frame = new JFrame();
	frame.setLayout(null);
	frame.setUndecorated(true);		
	frame.setSize(icon.getIconWidth(), icon.getIconHeight()+TEXT_HEIGHT);
	frame.setLocationRelativeTo(null);  
	frame.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
	frame.getRootPane().setBorder(new LineBorder(VisualConstants.SPLASH_BORDER_COLOR, 1));
	
	JLabel imageLabel = new JLabel(icon);
	imageLabel.setSize(icon.getIconWidth(), icon.getIconHeight());
	frame.add(imageLabel);
	imageLabel.setLocation(0, 0);
	textLabel = new JLabel();
	textLabel.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10));
	
	textLabel.setFont(VisualConstants.SPLASH_SCREEN_FONT);
	
	textPanel = new JPanel(new BorderLayout());
	textPanel.setLocation(0, icon.getIconHeight());
	textPanel.setSize(icon.getIconWidth(), TEXT_HEIGHT);
	textPanel.setBackground(Color.WHITE);
	textPanel.setOpaque(true);
	textPanel.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, VisualConstants.SPLASH_BORDER_COLOR));
	textPanel.add(textLabel);
	
	frame.add(textPanel);
	frame.setVisible(true);
}
 
源代码5 项目: radiance   文件: AutoScroll.java
/**
 * Creates the main frame for <code>this</code> sample.
 */
public AutoScroll() {
    super("Auto scroll");

    this.setLayout(new BorderLayout());

    // Create panel with custom painting logic - simple diagonal fill.
    JPanel samplePanel = new JPanel() {
        @Override
        protected void paintComponent(Graphics g) {
            Graphics2D graphics = (Graphics2D) g.create();
            graphics.setPaint(new GradientPaint(0, 0, new Color(100, 100, 255), getWidth(),
                    getHeight(), new Color(255, 100, 100)));
            graphics.fillRect(0, 0, getWidth(), getHeight());
            graphics.dispose();
        }
    };
    samplePanel.setPreferredSize(new Dimension(800, 400));
    samplePanel.setSize(this.getPreferredSize());
    samplePanel.setMinimumSize(this.getPreferredSize());

    final JScrollPane scrollPane = new JScrollPane(samplePanel);
    this.add(scrollPane, BorderLayout.CENTER);

    JPanel controls = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    final JCheckBox hasAutoScroll = new JCheckBox("has auto scroll");
    hasAutoScroll.addActionListener((ActionEvent e) -> SwingUtilities.invokeLater(() -> {
        SubstanceCortex.ComponentScope.setAutomaticScrollPresence(scrollPane,
                hasAutoScroll.isSelected());
        repaint();
    }));
    controls.add(hasAutoScroll);
    this.add(controls, BorderLayout.SOUTH);

    this.setSize(400, 200);
    this.setLocationRelativeTo(null);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
 
源代码6 项目: COMP6237   文件: MainMenu.java
/**
 * Construct the UI
 */
public MainMenu() {
	final List<LectureObject> lectures = getLectures();

	this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
	tabs = new JTabbedPane();
	final List<JButton> runBtns = new ArrayList<JButton>();
	for (final LectureObject l : lectures) {
		final Component lp = createLecturePanel(l, runBtns);
		tabs.addTab(l.lecture.title(), lp);
	}

	tabs.addChangeListener(new ChangeListener() {
		@Override
		public void stateChanged(ChangeEvent e) {
			final int idx = tabs.getSelectedIndex();
			final JRootPane root = MainMenu.this.getRootPane();

			if (root != null && idx >= 0)
				root.setDefaultButton(runBtns.get(idx));
		}
	});

	add(tabs);

	final JPanel info = new JPanel(new GridLayout(0, 1));
	info.setPreferredSize(new Dimension(800, 30));
	info.setSize(info.getPreferredSize());
	info.setMaximumSize(info.getPreferredSize());

	final JLabel link = Utils.linkify("http://comp6237.ecs.soton.ac.uk", "http://comp6237.ecs.soton.ac.uk",
			"Go to the course web site");
	link.setHorizontalAlignment(SwingConstants.CENTER);
	info.add(link);

	add(info);
}
 
源代码7 项目: jdk8u-jdk   文件: CursorOverlappedPanelsTest.java
private static JPanel createPanel(Point location, boolean enabled) {
    final JPanel panel = new JPanel();
    panel.setOpaque(false);
    panel.setEnabled(enabled);
    panel.setSize(new Dimension(200, 200));
    panel.setLocation(location);
    panel.setBorder(BorderFactory.createTitledBorder(
            enabled ? "Enabled" : "Disabled"));
    panel.setCursor(Cursor.getPredefinedCursor(
            enabled ? Cursor.CROSSHAIR_CURSOR : Cursor.DEFAULT_CURSOR));
    System.out.println("cursor: " + Cursor.getPredefinedCursor(enabled ? Cursor.CROSSHAIR_CURSOR : Cursor.DEFAULT_CURSOR));
    return panel;
}
 
源代码8 项目: hottub   文件: CursorOverlappedPanelsTest.java
private static JPanel createPanel(Point location, boolean enabled) {
    final JPanel panel = new JPanel();
    panel.setOpaque(false);
    panel.setEnabled(enabled);
    panel.setSize(new Dimension(200, 200));
    panel.setLocation(location);
    panel.setBorder(BorderFactory.createTitledBorder(
            enabled ? "Enabled" : "Disabled"));
    panel.setCursor(Cursor.getPredefinedCursor(
            enabled ? Cursor.CROSSHAIR_CURSOR : Cursor.DEFAULT_CURSOR));
    System.out.println("cursor: " + Cursor.getPredefinedCursor(enabled ? Cursor.CROSSHAIR_CURSOR : Cursor.DEFAULT_CURSOR));
    return panel;
}
 
源代码9 项目: freecol   文件: EmigrationDialog.java
/**
 * The constructor to use.
 *
 * @param freeColClient The {@code FreeColClient} for the game.
 * @param frame The owner frame.
 * @param europe The {@code Europe} where we can find the
 *     units that are prepared to emigrate.
 * @param foy Is this emigration due to a fountain of youth?
 */
public EmigrationDialog(FreeColClient freeColClient, JFrame frame,
        Europe europe, boolean foy) {
    super(freeColClient, frame);
    final List<AbstractUnit> recruitables
        = new ArrayList<>(europe.getExpandedRecruitables(false));

    JTextArea header
        = Utility.localizedTextArea("emigrationDialog.chooseImmigrant");
    if (foy) {
        header.insert(Messages.message(LostCityRumour.RumourType.FOUNTAIN_OF_YOUTH.getDescriptionKey())
                      + "\n\n", 0);
    }

    JPanel panel = new MigPanel(new MigLayout("wrap 1", "[fill]", ""));
    panel.add(header, "wrap 20");
    panel.setSize(panel.getPreferredSize());

    List<ChoiceItem<Integer>> c = choices();
    int i = Europe.MigrationType.getDefaultSlot();
    AbstractUnit a0 = recruitables.remove(0);
    c.add(new ChoiceItem<>(Messages.message(a0.getSingleLabel()), i++)
        .defaultOption()
        .setIcon(new ImageIcon(getSmallAbstractUnitImage(a0))));
    for (AbstractUnit au : recruitables) {
        c.add(new ChoiceItem<>(Messages.message(au.getSingleLabel()), i++)
            .setIcon(new ImageIcon(getSmallAbstractUnitImage(au))));
    }

    initializeChoiceDialog(frame, false, panel, null, null, c);
}
 
源代码10 项目: hottub   文件: javax_swing_JLayeredPane.java
private static void init(JLayeredPane pane, int layer, int x, int y, int w, int h, Color color) {
    JPanel panel = new JPanel();
    panel.setBackground(color);
    panel.setLocation(x, y);
    panel.setSize(w, h);
    pane.add(panel, new Integer(layer));
}
 
private static JPanel createPanel(Point location, boolean enabled) {
    final JPanel panel = new JPanel();
    panel.setOpaque(false);
    panel.setEnabled(enabled);
    panel.setSize(new Dimension(200, 200));
    panel.setLocation(location);
    panel.setBorder(BorderFactory.createTitledBorder(
            enabled ? "Enabled" : "Disabled"));
    panel.setCursor(Cursor.getPredefinedCursor(
            enabled ? Cursor.CROSSHAIR_CURSOR : Cursor.DEFAULT_CURSOR));
    System.out.println("cursor: " + Cursor.getPredefinedCursor(enabled ? Cursor.CROSSHAIR_CURSOR : Cursor.DEFAULT_CURSOR));
    return panel;
}
 
private static void init(JLayeredPane pane, int layer, int x, int y, int w, int h, Color color) {
    JPanel panel = new JPanel();
    panel.setBackground(color);
    panel.setLocation(x, y);
    panel.setSize(w, h);
    pane.add(panel, new Integer(layer));
}
 
源代码13 项目: jdk8u-dev-jdk   文件: javax_swing_JLayeredPane.java
private static void init(JLayeredPane pane, int layer, int x, int y, int w, int h, Color color) {
    JPanel panel = new JPanel();
    panel.setBackground(color);
    panel.setLocation(x, y);
    panel.setSize(w, h);
    pane.add(panel, new Integer(layer));
}
 
源代码14 项目: ShootPlane   文件: Top10ScorePanel.java
private void initComponents(MainFrame mainFrame) {
this.top10ScoreLabel = new JLabel("<html><font size='5'>Top 10 Scores</font></html>");
JPanel labelPanel = new JPanel();
labelPanel.setOpaque(false);
labelPanel.add(top10ScoreLabel);

JPanel scorePanel = new JPanel();
GridLayout gridLayout = new GridLayout(12, 1, 0, 5);
scorePanel.setLayout(gridLayout);
scorePanel.setOpaque(false);

scorePanel.add(labelPanel);

this.scoreButtons = new GameButton[SCORE_COUNT];
for (int i = 0; i < SCORE_COUNT; i++) {
    this.scoreButtons[i] = new GameButton();
    scorePanel.add(this.scoreButtons[i]);
}

this.okButton = new GameButton("OK");
this.okButton.setActionCommand(OK_BUTTON);
this.okButton.addActionListener(mainFrame);
scorePanel.add(okButton);

Dimension d = new Dimension(Config.POP_UP_SCORE_PANEL_WIDTH, Config.POP_UP_SCORE_PANEL_HEIGHT);
scorePanel.setSize(d);
scorePanel.setPreferredSize(d);

this.add(scorePanel);
this.setOpaque(false);
   }
 
源代码15 项目: COMP6237   文件: KMeansDemo.java
@Override
public Component getComponent(int width, int height) throws IOException {
	final JPanel base = new JPanel();
	base.setOpaque(false);
	base.setPreferredSize(new Dimension(width, height));
	base.setLayout(new BoxLayout(base, BoxLayout.Y_AXIS));

	image = new MBFImage(width, height - 50, ColourSpace.RGB);
	renderer = image.createRenderer(RenderHints.ANTI_ALIASED);
	resetImage();

	ic = new DisplayUtilities.ImageComponent(true, false);
	ic.setShowPixelColours(false);
	ic.setShowXYPosition(false);
	ic.setAllowPanning(false);
	ic.setAllowZoom(false);
	ic.addMouseListener(this);
	ic.addMouseMotionListener(this);
	base.add(ic);

	final JPanel controls = new JPanel();
	controls.setPreferredSize(new Dimension(width, 50));
	controls.setMaximumSize(new Dimension(width, 50));
	controls.setSize(new Dimension(width, 50));

	clearBtn = new JButton("Clear");
	clearBtn.setActionCommand("button.clear");
	clearBtn.addActionListener(this);
	controls.add(clearBtn);

	controls.add(new JSeparator(SwingConstants.VERTICAL));
	controls.add(new JLabel("K:"));

	kSpn = new JSpinner(new SpinnerNumberModel(1, 1, 10, 1));
	controls.add(kSpn);

	controls.add(new JSeparator(SwingConstants.VERTICAL));
	controls.add(new JLabel("Distance:"));

	distCombo = new JComboBox<String>();
	distCombo.addItem("Euclidean");
	distCombo.addItem("Manhatten");
	distCombo.addItem("Cosine Distance");
	controls.add(distCombo);

	controls.add(new JSeparator(SwingConstants.VERTICAL));

	runBtn = new JButton("Run KMeans");
	runBtn.setActionCommand("button.run");
	runBtn.addActionListener(this);
	controls.add(runBtn);

	controls.add(new JSeparator(SwingConstants.VERTICAL));

	cnclBtn = new JButton("Cancel");
	cnclBtn.setEnabled(false);
	cnclBtn.setActionCommand("button.cancel");
	cnclBtn.addActionListener(this);
	controls.add(cnclBtn);

	base.add(controls);

	updateImage();

	return base;
}
 
源代码16 项目: COMP6237   文件: SOMDemo.java
@Override
public Component getComponent(int width, int height) throws IOException {
	final JPanel base = new JPanel();
	base.setOpaque(false);
	base.setPreferredSize(new Dimension(width, height));
	base.setLayout(new BoxLayout(base, BoxLayout.Y_AXIS));

	image = new MBFImage(width, height - 56, ColourSpace.RGB);
	som = new float[(height - 56) / somfactor][width / somfactor][rawdata.getTerms().size()];
	renderer = image.createRenderer(RenderHints.ANTI_ALIASED);
	resetImage();

	ic = new DisplayUtilities.ImageComponent(true, false);
	ic.setShowPixelColours(false);
	ic.setShowXYPosition(false);
	ic.setAllowPanning(false);
	ic.setAllowZoom(false);
	base.add(ic);

	final JPanel controls = new JPanel();
	controls.setPreferredSize(new Dimension(width, 56));
	controls.setMaximumSize(new Dimension(width, 56));
	controls.setSize(new Dimension(width, 56));

	controls.add(new JSeparator(SwingConstants.VERTICAL));

	runBtn = new JButton("Run SOM");
	runBtn.setActionCommand("button.run");
	runBtn.addActionListener(this);
	controls.add(runBtn);

	controls.add(new JSeparator(SwingConstants.VERTICAL));

	cnclBtn = new JButton("Cancel");
	cnclBtn.setEnabled(false);
	cnclBtn.setActionCommand("button.cancel");
	cnclBtn.addActionListener(this);
	controls.add(cnclBtn);

	base.add(controls);

	updateImage();

	return base;
}
 
源代码17 项目: COMP3204   文件: ArtARDemo.java
@Override
public JPanel getComponent(int width, int height) throws IOException {
	final JPanel container = new JPanel();
	container.setSize(width, height);
	container.setPreferredSize(container.getSize());

	final OverlayLayout overlay = new OverlayLayout(container);
	container.setLayout(overlay);

	labelField = new JEditorPane();
	labelField.setOpaque(false);
	labelField.setSize(640 - 50, 480 - 50);
	labelField.setPreferredSize(labelField.getSize());
	labelField.setMaximumSize(labelField.getSize());
	labelField.setContentType("text/html");

	// add a HTMLEditorKit to the editor pane
	final HTMLEditorKit kit = new HTMLEditorKit();
	labelField.setEditorKit(kit);

	final StyleSheet styleSheet = kit.getStyleSheet();
	styleSheet.addRule("body {color:#FF00FF; font-family:courier;}");
	styleSheet.addRule("h1 {font-size: 60pt}");
	styleSheet.addRule("h2 {font-size: 50pt }");

	final Document doc = kit.createDefaultDocument();
	labelField.setDocument(doc);

	// final GridBagConstraints gbc = new GridBagConstraints();
	// gbc.gridy = 1;
	// panel.add(labelField, gbc);
	container.add(labelField);
	// labelField.setAlignmentX(0.5f);
	// labelField.setAlignmentY(0.5f);

	final JPanel panel = super.getComponent(width, height);
	container.add(panel);

	vc.getDisplay().addVideoListener(this);

	isRunning = true;
	new Thread(this).start();

	return container;
}
 
源代码18 项目: COMP6237   文件: MeanShiftDemo.java
@Override
public Component getComponent(int width, int height) throws IOException {
	final JPanel base = new JPanel();
	base.setOpaque(false);
	base.setPreferredSize(new Dimension(width, height));
	base.setLayout(new BoxLayout(base, BoxLayout.Y_AXIS));

	image = new MBFImage(width, height - 50, ColourSpace.RGB);
	renderer = image.createRenderer(RenderHints.ANTI_ALIASED);
	resetImage();

	ic = new DisplayUtilities.ImageComponent(true, false);
	ic.setShowPixelColours(false);
	ic.setShowXYPosition(false);
	ic.setAllowPanning(false);
	ic.setAllowZoom(false);
	ic.addMouseListener(this);
	ic.addMouseMotionListener(this);
	base.add(ic);

	final JPanel controls = new JPanel();
	controls.setPreferredSize(new Dimension(width, 50));
	controls.setMaximumSize(new Dimension(width, 50));
	controls.setSize(new Dimension(width, 50));

	clearBtn = new JButton("Clear");
	clearBtn.setActionCommand("button.clear");
	clearBtn.addActionListener(this);
	controls.add(clearBtn);

	controls.add(new JSeparator(SwingConstants.VERTICAL));

	controls.add(new JLabel("H:"));
	hSpn = new JSpinner(new SpinnerNumberModel(30, 1, 100, 5));
	controls.add(hSpn);

	controls.add(new JSeparator(SwingConstants.VERTICAL));

	runBtn = new JButton("Run Mean Shift");
	runBtn.setActionCommand("button.run");
	runBtn.addActionListener(this);
	controls.add(runBtn);

	controls.add(new JSeparator(SwingConstants.VERTICAL));

	cnclBtn = new JButton("Cancel");
	cnclBtn.setEnabled(false);
	cnclBtn.setActionCommand("button.cancel");
	cnclBtn.addActionListener(this);
	controls.add(cnclBtn);

	base.add(controls);

	updateImage();

	return base;
}
 
源代码19 项目: COMP3204   文件: LineRANSACDemo.java
@Override
public Component getComponent(int width, int height) throws IOException {
	final JPanel base = new JPanel();
	base.setOpaque(false);
	base.setPreferredSize(new Dimension(width, height));
	base.setLayout(new BoxLayout(base, BoxLayout.Y_AXIS));

	image = new MBFImage(width, height - 50, ColourSpace.RGB);
	resetImage();

	ic = new DisplayUtilities.ImageComponent(true, false);
	ic.setShowPixelColours(false);
	ic.setShowXYPosition(false);
	ic.setAllowPanning(false);
	ic.setAllowZoom(false);
	ic.addMouseListener(this);
	ic.addMouseMotionListener(this);
	base.add(ic);

	final JPanel controls = new JPanel();
	controls.setPreferredSize(new Dimension(width, 50));
	controls.setMaximumSize(new Dimension(width, 50));
	controls.setSize(new Dimension(width, 50));

	clearBtn = new JButton("Clear");
	clearBtn.setActionCommand("button.clear");
	clearBtn.addActionListener(this);
	controls.add(clearBtn);

	controls.add(new JSeparator(SwingConstants.VERTICAL));

	runBtn = new JButton("Run RANSAC Estimator");
	runBtn.setActionCommand("button.run");
	runBtn.addActionListener(this);
	controls.add(runBtn);

	controls.add(new JSeparator(SwingConstants.VERTICAL));

	cnclBtn = new JButton("Cancel");
	cnclBtn.setEnabled(false);
	cnclBtn.setActionCommand("button.cancel");
	cnclBtn.addActionListener(this);
	controls.add(cnclBtn);

	base.add(controls);

	updateImage();

	return base;
}
 
源代码20 项目: marvinproject   文件: MarvinEditor.java
/**
	 * Constructs Marvin main class with arguments
	 * 
	 * @param a_args Arguments
	 * <p>
	 * NOTE: Marvin supports 2 arguments at initialization: 
	 * {@code windowBounds(x, y, width, height)} and {@code windowState(state)}.
	 * <br>
	 * These arguments are useful when it's working with 2 screens. 
	 * Assume second screen is set like "LEFT" and it has 1024x768 resolution. 
	 * It's possible opening Marvin directly to the second screen: 
	 * <br><br>
	 * <strong>java -cp ".";"./bin" kernel.Marvin windowBounds(-1024,0,800,600) windowState(max)</strong>
	 * <br><br>
	 * This way could help in working source code and IDE with the main screen and testing Marvin in other one.
	 */
	public MarvinEditor(String a_args[]) {
		super("MARVIN");
		loadMenuBar(); 		// Menu bars
		
		panelMain = new JPanel();
		titlep = BorderFactory.createTitledBorder("Image");
		panelMain.setBorder(titlep);
		panelMain.setSize(600, 600);
		panelMain.setLayout(new BorderLayout());
		add(panelMain);

		imagePanel = new MarvinImagePanel();
		imagePanel.enableHistory();		
		imagePanel.setImage(image);
		imageScrollPane = new JScrollPane(imagePanel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
		panelMain.add(imageScrollPane);
		
		// loads the File Chooser class.
		new JFileChooser();
		
		//performanceMeter = new MarvinPerformanceMeter();
		//add(performanceMeter.getPanel(), BorderLayout.SOUTH);

		newImage(500,500);
		treatArgs(a_args);
		marvin = this;
		
		setSize(800,600); 	// Default size
		setVisible(true);
	}