imageicon

How to add text next to image in jtable?

 ̄綄美尐妖づ 提交于 2019-12-31 07:24:07
问题 I have a three column jtable and want to have the first two columns have an Imageicon and a string right next to it. Currently I am displaying the ImageIcons like DefaultTableModel model = new DefaultTableModel(rows, columns) { @Override public Class<?> getColumnClass(int column) { switch (column) { case 0: case 1: return ImageIcon.class; case 2: return String.class; default: return Object.class; } } }; jTable.setModel(model); I did find this but don't know what goes in ... or how to set the

How to add an ImageIcon to a JToolBar

断了今生、忘了曾经 提交于 2019-12-31 03:20:29
问题 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

How to add jlabel image hovering?

人走茶凉 提交于 2019-12-31 02:09:08
问题 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

Align icon and JCheckbox in JPopupmenu

…衆ロ難τιáo~ 提交于 2019-12-31 01:11:22
问题 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? 回答1: Have a look at this, in order to achieve what you wanted, I did this, JCheckBoxMenuItem cbmi = new

Align icon and JCheckbox in JPopupmenu

时光怂恿深爱的人放手 提交于 2019-12-31 01:11:15
问题 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? 回答1: Have a look at this, in order to achieve what you wanted, I did this, JCheckBoxMenuItem cbmi = new

Java getClass().getResource(“file”) leads to NullPointerException

大城市里の小女人 提交于 2019-12-30 07:57:13
问题 I am following the zetcode Snake java games tutorial and always get this error: ImageIcon iid = new ImageIcon(this.getClass().getResource("ball.png")); ball = iid.getImage(); Exception in thread "main" java.lang.NullPointerException at javax.swing.ImageIcon.<init>(Unknown Source) at snake2.Board.<init>(Board.java:52) at snake2.Snake.<init>(Snake.java:10) at snake2.Snake.main(Snake.java:22) I actually just copied and pasted the code to see how it works. They are in the right packages too; but

Accessing image paths in Eclipse

梦想的初衷 提交于 2019-12-30 07:22:16
问题 I'm trying to access some images in my Java code. The code to call the images is below. public final ImageIcon whitePiece = new ImageIcon(getClass().getResource("Images/whitecircle.PNG")); public final ImageIcon blackPiece = new ImageIcon(getClass().getResource("Images/blackcircle.png")); public final ImageIcon tiePiece = new ImageIcon(getClass().getResource("Images/tiecircle.PNG")); public final ImageIcon boardPic = new ImageIcon(getClass().getResource("Images/gameboard.PNG")); However, this

Accessing image paths in Eclipse

痞子三分冷 提交于 2019-12-30 07:22:08
问题 I'm trying to access some images in my Java code. The code to call the images is below. public final ImageIcon whitePiece = new ImageIcon(getClass().getResource("Images/whitecircle.PNG")); public final ImageIcon blackPiece = new ImageIcon(getClass().getResource("Images/blackcircle.png")); public final ImageIcon tiePiece = new ImageIcon(getClass().getResource("Images/tiecircle.PNG")); public final ImageIcon boardPic = new ImageIcon(getClass().getResource("Images/gameboard.PNG")); However, this

Resizing image to fit in JLabel

前提是你 提交于 2019-12-28 07:05:16
问题 I am trying to load an image from directory and place it as an icon in JLabel . But when the image size is big it doesn't fit completely in the label. I tried resizing the image to fit in the label but its not working. May I know where I am going wrong? JFileChooser choose=new JFileChooser(); choose.showOpenDialog(null); File f=choose.getSelectedFile(); String filename=f.getAbsolutePath(); path.setText(filename); ImageIcon icon=new ImageIcon(filename); Image img=icon.getImage(); BufferedImage

Setting the default application icon image in Java swing on OS X

柔情痞子 提交于 2019-12-28 06:01:14
问题 I'm trying to set the icon image for a Jar file: setIconImage(new ImageIcon(getClass().getResource("logo.png")).getImage()); When running in Mac OS X 10.7.4 I get the following error: Jun 28 15:21:40 (my dhcp) java[73383] <Error>: CGContextGetCTM: invalid context 0x0 Jun 28 15:21:40 (my dhcp) java[73383] <Error>: CGContextSetBaseCTM: invalid context 0x0 Jun 28 15:21:40 (my dhcp) java[73383] <Error>: CGContextGetCTM: invalid context 0x0 Jun 28 15:21:40 (my dhcp) java[73383] <Error>: