imageicon

Different imageIcon in different cells in JTable

爱⌒轻易说出口 提交于 2019-12-02 04:24:23
I think I got the imageIcon to show up differently in each cell but for some reason when I compile it, the images don't show up. It displays the name of the image but the image itself doesn't show up. Here is an image. http://i49.tinypic.com/r9ibrn.jpg public class movies extends JFrame { public movies() { initComponents(); } private void initComponents() { panel = new JPanel(); logo = new JLabel(); pane = new JScrollPane(); setDefaultCloseOperation(EXIT_ON_CLOSE); setBackground(new Color(255, 255, 204)); setResizable(false); panel.setBackground(new Color(51, 51, 51)); panel.setPreferredSize

Layout Manager for background images and text

回眸只為那壹抹淺笑 提交于 2019-12-02 03:05:09
问题 I'm trying to think of the best layout manager to achieve the picture below. I know absolute positioning is what I am used to, but I can't get the background image using this. GridBagLayout is excellent, but horrifically hard when ever I try I get a separate image for each grid. Does anyone know an easy way out of this, or easy code to achieve the following? 回答1: There are a number of ways you can achieve this. The simplest might be to just use what's already available ... If you don't need

Images in JTable cells off by one pixel?

本秂侑毒 提交于 2019-12-02 02:10:47
问题 So, I'm able to load images into my JTable's cells now, but for some reason the graphics are all shifted to the right by one pixel, allowing me to see the JTable's background. Any ideas? Sorry if my formatting's off; still not entirely used to this markup. public static void main(String[] args) { final int rows = 16; final int columns = 16; final int dimTile = 32; JFrame frame = new JFrame("test"); JTable table = new JTable(rows, columns); table.setIntercellSpacing(new Dimension(0, 0)); table

How to add an ImageIcon to a JToolBar

半城伤御伤魂 提交于 2019-12-02 01:52:37
I am trying to add a icon to a toolbar but what is the best place to put it in? My desktop or should I make a new file in the project file or add all the pictures in because it is not showing and this is my code: JToolBar toolBar = new JToolBar(); String[] iconFiles = {"pen-icon","",""}; String[] buttonLabels = {"New","Open","Save"}; icon = new ImageIcon[iconFiles.length]; Obutton = new JButton[buttonLabels.length]; for (int i = 0; i < buttonLabels.length; ++i) { icon[i] = new ImageIcon(iconFiles[i]); Obutton[i] = new JButton(icon[i]); Obutton[i].setToolTipText(buttonLabels[i]); if (i == 3)

Images in JTable cells off by one pixel?

假装没事ソ 提交于 2019-12-02 01:30:34
So, I'm able to load images into my JTable's cells now, but for some reason the graphics are all shifted to the right by one pixel, allowing me to see the JTable's background. Any ideas? Sorry if my formatting's off; still not entirely used to this markup. public static void main(String[] args) { final int rows = 16; final int columns = 16; final int dimTile = 32; JFrame frame = new JFrame("test"); JTable table = new JTable(rows, columns); table.setIntercellSpacing(new Dimension(0, 0)); table.setShowGrid(false); table.setBackground(Color.cyan); table.setTableHeader(null); table.setRowHeight

How can I drag images with the mouse cursor in Java GUI?

不羁岁月 提交于 2019-12-02 00:52:00
// my code that calls upon n images in a directory to be placed on the JPanel public void imageAdder(int n, String name){ BufferedImage myPic = null; for (int i = 0; i <= n; i++){ try { myPic = ImageIO.read(new File("Images/" + name + i + ".jpg")); } catch (Exception e){ System.out.println("no file man cmon"); } JLabel picLabel = new JLabel(new ImageIcon(myPic)); // picLabel.setBounds(mouseX, mouseY, 100, 50); // picLabel.addMouseMotionListener(this); // picLabel.addMouseListener(this); canvas.add(picLabel); }} I read about the class DragSource and how there's a method that drags things of

Layout Manager for background images and text

六眼飞鱼酱① 提交于 2019-12-01 23:38:53
I'm trying to think of the best layout manager to achieve the picture below. I know absolute positioning is what I am used to, but I can't get the background image using this. GridBagLayout is excellent, but horrifically hard when ever I try I get a separate image for each grid. Does anyone know an easy way out of this, or easy code to achieve the following? There are a number of ways you can achieve this. The simplest might be to just use what's already available ... If you don't need the background to be scaled at run-time (ie you can get away with a non-resizable window), simply using a

Packaging a program containing images

十年热恋 提交于 2019-12-01 23:25:34
I'm having massive issues packaging my java program which contains images into a jar for conversion into and executable file. The images have been used in the background of the program and buttons. Please see the diagram below which shows the program I desire to convert to a jar. IMAGE As you see above the program runs OK. I created the same program with no custom background and custom buttons containing no images and I successfully packaged it into a jar and subsequently into an .exe file. With regards to drawing my background I'm doing this as follows: public void paintComponent(Graphics g)

How to add jlabel image hovering?

﹥>﹥吖頭↗ 提交于 2019-12-01 22:21:02
How would I go upon adding JLabel hovering? Like when you move your mouse over top a JLabel a and new image will overlap it. I know how to make it work with buttons, but the same technique will not work for JLabel s. Will anyone guide me towards adding JLabel hovering? Please and thanks. package src; import java.awt.Dimension; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; /* * @Author - 0x29A * * */ public class Jframe { public static void main(final String args[]) { /* * @Images */ final ImageIcon icon = new ImageIcon("Data/button.png"); final JLabel

Align icon and JCheckbox in JPopupmenu

僤鯓⒐⒋嵵緔 提交于 2019-12-01 20:12:08
I have a Problem with some icons and check-boxes in a JPopupMenu . The Check-boxes and Icons are not aligned The Items are created like: JMenuItem deleteAttributeMenuItem = new JMenuItem(locale.getString("TREE_AttrDelete"), iconDelete); JMenuItem primaryKeyAttributeMenuItem = new JCheckBoxMenuItem(locale.getString("TREE_AttrChkBoxPK")); Please take a look at the picture: Any tips? Have a look at this, in order to achieve what you wanted, I did this, JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem("Check Me", null, true); cbmi.setMargin(new java.awt.Insets(5, 25, 5, 5)); cbmi.setIconTextGap(15);