Java Code Examples for javax.swing.JLabel#setSize()

The following examples show how to use javax.swing.JLabel#setSize() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private void displayWeight(List<Double> currentKernel) {

		JFrame frame = new JFrame("Weight Visualiser: ");
		frame.setSize(400, 400);

		JLabel label = new JLabel();
		Dimension d = new Dimension(kernel.getWidth() * RATIO, kernel.getHeight() * RATIO);
		label.setSize(d);
		label.setPreferredSize(d);

		frame.getContentPane().add(label, BorderLayout.CENTER);
		frame.pack();
		frame.setVisible(true);

		BufferedImage image = new BufferedImage(kernel.getWidth(), kernel.getHeight(), BufferedImage.TYPE_BYTE_GRAY);

		int[] rgb = convertWeightToRGB(currentKernel);
		image.setRGB(0, 0, kernel.getWidth(), kernel.getHeight(), rgb, 0, kernel.getWidth());
		label.setIcon(new ImageIcon(image.getScaledInstance(kernel.getWidth() * RATIO, kernel.getHeight() * RATIO, Image.SCALE_SMOOTH)));

	}
 
Example 2
Source Project: Jupiter   File: Splash.java    License: GNU General Public License v3.0 6 votes vote down vote up
public Splash(String splashText) throws InterruptedException, IOException{
		BufferedImage image;
		image = ImageIO.read(this.getClass().getClassLoader().getResourceAsStream("lang/jpn/Jupiter.jpg"));
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		label = new JLabel(new ImageIcon(image));
		label.setSize(408, 48);
		text = new JLabel(splashText);
		text.setSize(200, 30);
		text.setBackground(Color.BLACK);
		text.setForeground(Color.WHITE);
		text.setFont(new Font("MS Pゴシック", Font.PLAIN, 20));
		this.setSize(screenSize.width, 48);
		this.setLocation(0, 0);
		this.getContentPane().setBackground(Color.BLACK);
		this.setLayout(new BorderLayout());
		this.getContentPane().add(label, BorderLayout.CENTER);
		this.getContentPane().add(text, BorderLayout.EAST);
		this.setResizable(false);
		this.setUndecorated(true);
		this.setVisible(true);
		Thread.sleep(2000);
		this.setVisible(false);
}
 
Example 3
private void addTab(String tabText, JPanel panel, int tabIndex) {

        JTabbedPane tracerReportTabbedPane = getTracerReportTabbedPane();

        JLabel tabLabel = new JLabel(tabText);
        Font labelFont = tabLabel.getFont();
        Font tabFont = labelFont.deriveFont(Font.BOLD, 12);
        Dimension dim = new Dimension(140, 26);
        tabLabel.setFont(tabFont);
        tabLabel.setSize(dim);
        tabLabel.setPreferredSize(dim);
        tabLabel.setHorizontalAlignment(SwingConstants.CENTER);

        tracerReportTabbedPane.addTab(tabText, panel);
        tracerReportTabbedPane.setTabComponentAt(tabIndex, tabLabel);
    }
 
Example 4
private static void createAndShowGUI() {

        try {
            UIManager.setLookAndFeel(new TestLookAndFeel());

            JLabel label = new JLabel("Test Label");
            label.setSize(SIZE, SIZE);
            TitledBorder border = new TitledBorder("ABCDEF");
            label.setBorder(new TitledBorder(border));

            if (useLAF) {
                UIManager.setLookAndFeel(new NimbusLookAndFeel());
            } else {
                UIManager.getDefaults().put("LabelUI", MetalLabelUI.class.getName());
            }

            SwingUtilities.updateComponentTreeUI(label);

            paintToImage(label);

        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
 
Example 5
Source Project: jaamsim   File: YUVImage.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Debug, show this image in a JFrame
 * @param scale
 * @param withChroma
 * @param title
 */
public void show(int scale, boolean withChroma, String title) {
	BufferedImage image = new BufferedImage(width*scale, height*scale, BufferedImage.TYPE_INT_RGB);

	for (int y = 0; y < height; ++y) {
		for (int x = 0; x < width; ++x) {
			int chX = x >> 1;
			int chY = y >> 1;
			int chW = width >> 1;
			int index = y*width + x;
			int chIndex = chY*chW + chX;
			int val = 0;
			if (withChroma) {
				val = Util.yuvToRGBInt(Util.getUByte(yPlane, index), Util.getUByte(uPlane, chIndex), Util.getUByte(vPlane, chIndex));
			} else {
				val = Util.yuvToRGBInt(Util.getUByte(yPlane, index), 128, 128);
			}

			for (int j = 0; j < scale; ++j) {
				for (int i = 0; i < scale; ++i) {
					image.setRGB(x*scale+i, y*scale+j, val);
				}
			}
		}
	}

	JFrame frame = new JFrame(title);

	ImageIcon icon = new ImageIcon(image);

	JLabel label = new JLabel(icon, JLabel.CENTER);
	label.setSize(width*scale, height*scale);
	frame.add(label);
	frame.pack();

	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

	frame.setVisible(true);

}
 
Example 6
Source Project: chipster   File: SplashScreen.java    License: MIT License 5 votes vote down vote up
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);
}
 
Example 7
private static Icon centeredIcon(final Icon icon, final int width, final int height) {
    JLabel l = new JLabel(icon);
    l.setIconTextGap(0);
    l.setBorder(null);
    l.setSize(width, height);
    
    BufferedImage img = new BufferedImage(l.getWidth(), l.getHeight(), BufferedImage.TYPE_INT_ARGB);
    l.paint(img.getGraphics());
    
    return new ImageIcon(img);
}
 
Example 8
ColorCustomizationTest() {
    label = new JLabel();
    label.setSize(200, 100);

    g = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB).getGraphics();
}
 
Example 9
ColorCustomizationTest() {
    label = new JLabel();
    label.setSize(200, 100);

    g = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB).getGraphics();
}
 
Example 10
ColorCustomizationTest() {
    label = new JLabel();
    label.setSize(200, 100);

    g = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB).getGraphics();
}
 
Example 11
ColorCustomizationTest() {
    label = new JLabel();
    label.setSize(200, 100);

    g = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB).getGraphics();
}
 
Example 12
Source Project: SikuliX1   File: TransitionDialog.java    License: MIT License 4 votes vote down vote up
void init(String text){

      setBackground(Color.yellow);
      setForeground(Color.black);

      JPanel content = new JPanel();
      content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));
      add(content);

      textPane = new TextPane();
      textPane.setText(text);
      textPane.setBorder(BorderFactory.createEmptyBorder(3, 5, 3, 5));

      Color darkyellow = new Color(238,185,57);

      titleBar = new JLabel();
      titleBar.setFont(new Font("sansserif", Font.BOLD, 14));
      titleBar.setBackground(darkyellow);
      titleBar.setOpaque(true);
      titleBar.setBorder(BorderFactory.createEmptyBorder(5, 5, 3, 5));
      titleBar.setSize(titleBar.getPreferredSize());
      titleBar.setVisible(false);

      buttons = new Box(BoxLayout.X_AXIS);
      defaultButton = new Button("Close");
      buttons.add(defaultButton);
      buttons.setBorder(BorderFactory.createEmptyBorder(15,5,5,5));

      content.add(titleBar);
      content.add(textPane);
      content.add(buttons);

      // this allows the title bar to take the whole width of the dialog box
      titleBar.setMaximumSize(new Dimension(Integer.MAX_VALUE,Integer.MAX_VALUE));
      buttons.setMaximumSize(new Dimension(Integer.MAX_VALUE,Integer.MAX_VALUE));
      textPane.setMaximumSize(new Dimension(Integer.MAX_VALUE,Integer.MAX_VALUE));

      // these allow all the parts to left aligned
      titleBar.setAlignmentX(Component.LEFT_ALIGNMENT);
      textPane.setAlignmentX(Component.LEFT_ALIGNMENT);
      buttons.setAlignmentX(Component.LEFT_ALIGNMENT);

      // these are meant to prevent the message box from stealing
      // focus when it's clicked, but they don't seem to work
//      setFocusableWindowState(false);
//      setFocusable(false);

      // this allows the window to be dragged to another location on the screen
      ComponentMover cm = new ComponentMover();
      cm.registerComponent(this);

      pack();
   }
 
Example 13
private void ShowDateInterpretationPanel(
        AliquotInterface aliquot,
        ValueModel sampleDateModel,
        int width,
        int offset) {

    JPanel ageInterpPanel = new JPanel();
    if (((SampleDateModel)sampleDateModel).isPreferred()){
        ageInterpPanel.setBackground(new java.awt.Color(255, 204, 204));
    }else {
        ageInterpPanel.setBackground(new java.awt.Color(255, 255, 204));
    }

    org.jdesktop.layout.GroupLayout jPanel1Layout =
            new org.jdesktop.layout.GroupLayout(ageInterpPanel);
    ageInterpPanel.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(
            org.jdesktop.layout.GroupLayout.LEADING).add(0, width, Short.MAX_VALUE));
    jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(
            org.jdesktop.layout.GroupLayout.LEADING).add(0, 100, Short.MAX_VALUE));

    ageInterpPanel.setBounds(0, offset * 120 + 25, width, 100);

    JLabel aliquotName_label = new JLabel();
    aliquotName_label.setHorizontalAlignment(SwingConstants.CENTER);
    aliquotName_label.setBorder(
            javax.swing.BorderFactory.createLineBorder(Color.black));
    aliquotName_label.setText(
            "Aliquot: " + aliquot.getAliquotName().trim());
    aliquotName_label.setSize(width, 10);


    try {
        JLabel ageInterpName_label = new JLabel(sampleDateModel.getName());
        org.jdesktop.layout.GroupLayout ageInterpPanelLayout =
                new org.jdesktop.layout.GroupLayout(ageInterpPanel);
        ageInterpPanel.setLayout(ageInterpPanelLayout);
        ageInterpPanelLayout.setHorizontalGroup(
                ageInterpPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(ageInterpPanelLayout.createSequentialGroup().add(ageInterpName_label).addContainerGap(161, Short.MAX_VALUE)).add(aliquotName_label, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 206, Short.MAX_VALUE));
        ageInterpPanelLayout.setVerticalGroup(
                ageInterpPanelLayout.createParallelGroup(//
                org.jdesktop.layout.GroupLayout.LEADING).//
                add(ageInterpPanelLayout.createSequentialGroup().//
                add(aliquotName_label).//
                //addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED).//
                add(ageInterpName_label).//
                addContainerGap(60, Short.MAX_VALUE)));
    } catch (Exception e) {
    }


    add(ageInterpPanel);//, javax.swing.JLayeredPane.DEFAULT_LAYER);
}
 
Example 14
public FeaturesView(Component defaultView, String buttonString) {
    if (UIUtils.isOracleLookAndFeel()) {
        setOpaque(true);
        setBackground(UIUtils.getProfilerResultsBackground());
    } else {
        setOpaque(false);
    }
    setBorder(BorderFactory.createEmptyBorder());
    setLayout(new BorderLayout(0, 0));
    
    if (defaultView != null) {
        JScrollPane sp = new JScrollPane(defaultView, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER) {
            public Dimension getMinimumSize() { return getPreferredSize(); }
        };
        sp.getVerticalScrollBar().setUnitIncrement(20);
        sp.setBorder(null);
        sp.setViewportBorder(null);

        this.defaultView = sp;
        add(this.defaultView, BorderLayout.CENTER);
    } else {
        this.defaultView = null;
    }
    
    if (buttonString != null) {
        hintLabel = new JLabel();
        hintLabel.setIcon(Icons.getIcon(GeneralIcons.INFO));
        hintLabel.setIconTextGap(hintLabel.getIconTextGap() + 1);
        hintLabel.setOpaque(false);
        
        Font font = new JToolTip().getFont();
        
        Color f = hintLabel.getForeground();
        int r = f.getRed() + 70;
        if (r > 255) r = f.getRed() - 70; else r = Math.min(r, 70);
        int g = f.getGreen() + 70;
        if (g > 255) g = f.getRed() - 70; else g = Math.min(g, 70);
        int b = f.getBlue() + 70;
        if (b > 255) b = f.getRed() - 70; else b = Math.min(b, 70);
        hintLabel.setText("<html><body text=\"rgb(" + r + ", " + g + ", " + b + ")\" style=\"font-size: " + //NOI18N
                          (font.getSize()) + "pt; font-family: " + font.getName() + ";\">" + //NOI18N
                          Bundle.FeaturesView_noData("<b>" + buttonString + "</b>") + "</body></html>"); //NOI18N
        
        hintLabel.setSize(hintLabel.getPreferredSize());
        
        Color c = UIUtils.getProfilerResultsBackground();
        hintColor = Utils.checkedColor(new Color(c.getRed(), c.getGreen(), c.getBlue(), 245));
    } else {
        hintColor = null;
    }
}
 
Example 15
ColorCustomizationTest() {
    label = new JLabel();
    label.setSize(200, 100);

    g = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB).getGraphics();
}
 
Example 16
ColorCustomizationTest() {
    label = new JLabel();
    label.setSize(200, 100);

    g = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB).getGraphics();
}
 
Example 17
Source Project: netbeans   File: FeaturesView.java    License: Apache License 2.0 4 votes vote down vote up
public FeaturesView(Component defaultView, String buttonString) {
    if (UIUtils.isOracleLookAndFeel()) {
        setOpaque(true);
        setBackground(UIUtils.getProfilerResultsBackground());
    } else {
        setOpaque(false);
    }
    setBorder(BorderFactory.createEmptyBorder());
    setLayout(new BorderLayout(0, 0));
    
    if (defaultView != null) {
        JScrollPane sp = new JScrollPane(defaultView, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER) {
            public Dimension getMinimumSize() { return getPreferredSize(); }
        };
        sp.getVerticalScrollBar().setUnitIncrement(20);
        sp.setBorder(null);
        sp.setViewportBorder(null);

        this.defaultView = sp;
        add(this.defaultView, BorderLayout.CENTER);
    } else {
        this.defaultView = null;
    }
    
    if (buttonString != null) {
        hintLabel = new JLabel();
        hintLabel.setIcon(Icons.getIcon(GeneralIcons.INFO));
        hintLabel.setIconTextGap(hintLabel.getIconTextGap() + 1);
        hintLabel.setOpaque(false);
        
        Font font = new JToolTip().getFont();
        
        Color f = hintLabel.getForeground();
        int r = f.getRed() + 70;
        if (r > 255) r = f.getRed() - 70; else r = Math.min(r, 70);
        int g = f.getGreen() + 70;
        if (g > 255) g = f.getRed() - 70; else g = Math.min(g, 70);
        int b = f.getBlue() + 70;
        if (b > 255) b = f.getRed() - 70; else b = Math.min(b, 70);
        hintLabel.setText("<html><body text=\"rgb(" + r + ", " + g + ", " + b + ")\" style=\"font-size: " + //NOI18N
                          (font.getSize()) + "pt; font-family: " + font.getName() + ";\">" + //NOI18N
                          Bundle.FeaturesView_noData("<b>" + buttonString + "</b>") + "</body></html>"); //NOI18N
        
        hintLabel.setSize(hintLabel.getPreferredSize());
        
        Color c = UIUtils.getProfilerResultsBackground();
        hintColor = Utils.checkedColor(new Color(c.getRed(), c.getGreen(), c.getBlue(), 245));
    } else {
        hintColor = null;
    }
}
 
Example 18
ColorCustomizationTest() {
    label = new JLabel();
    label.setSize(200, 100);

    g = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB).getGraphics();
}
 
Example 19
ColorCustomizationTest() {
    label = new JLabel();
    label.setSize(200, 100);

    g = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB).getGraphics();
}
 
Example 20
ColorCustomizationTest() {
    label = new JLabel();
    label.setSize(200, 100);

    g = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB).getGraphics();
}