imageicon

Getting jLabel image url in Java

假装没事ソ 提交于 2019-12-12 01:57:29
问题 I'll make it short. I've put a jLbl_show and in a if condition I've set an image for it. if(int c==1){ jLbl_show0.setIcon(new ImageIcon(getClass().getResource("/img/wrong.png"))); } else{ jLbl_show0.setIcon(new ImageIcon(getClass().getResource("/img/ok.png"))); } But, as now the image is set i need to take the image URL to another condition . which is like; if(imageURL is "/img/ok.png"){ do somthing } elseif (imgURL is "/img/wrong.png"){ do something } is there a way to do this? 回答1: do

Applet image missing

↘锁芯ラ 提交于 2019-12-12 01:47:16
问题 Hello again Stackoverflow members, The CatchTheCreature Applet class is supposed to display an image being repainted in different locations by a time delay, but for some reason the image is not being displayed. import java.awt.Color; import java.awt.Graphics; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.util.Random; import javax.swing.ImageIcon; import javax.swing.JApplet; import

Inserting an Image into a JTable

戏子无情 提交于 2019-12-11 23:15:57
问题 I'm having an issue inserting images into a JTable. Ive searched and found there are 2 ways. You can either override the getcolumnclass of the tablemodel or create your custom tablecellrender. I chose to make my own cell renderer with this code: public class MyRenderer extends DefaultTableCellRenderer { /* * @see TableCellRenderer#getTableCellRendererComponent(JTable, Object, boolean, boolean, int, int) */ public Component getTableCellRendererComponent(JTable table, Object value, boolean

How to get ImageIcon from Enum?

删除回忆录丶 提交于 2019-12-11 23:05:47
问题 My Gui class pulls up an ExceptioninInitializerError due to NullPointerException . My question is, how can I get information from my enum (such as the ImageIcon of Rock) and use it to setIcon of my JPanel without getting this error. EDIT: When I click the Rock Button on the GUI, this is the error that is brought up Exception in thread "AWT-EventQueue-0" java.lang.ExceptionInInitializerError at rockPaperScissors.RockPaperScissorsGui$2.actionPerformed(RockPaperScissorsGui.java:156) at javax

icon in JTabbedPane is not shown

爷,独闯天下 提交于 2019-12-11 20:40:09
问题 I have a problem with my tabs: JTabbedPane tab = new JTabbedPane(); frame.add(tab, BorderLayout.CENTER); JPanel contact = new JPanel(); contact.add(backgroundContact); tab.add("Contacto", contact); //tab.addTab("Contacto",new ImageIcon("images/image2.gif"), contact,""); JPanel schedule = new JPanel(); schedule.add(backgroundSchedule); tab.add("Horario", schedule); //tab.addTab("Horario", new ImageIcon("images/image2.gif"), schedule,""); JPanel cost = new JPanel(); cost.add(backgroundCost);

How can I force an ImageIcon to be a certain size?

≯℡__Kan透↙ 提交于 2019-12-11 19:59:10
问题 Currently, I use this code: public class Test extends JFrame { static Test t = null; public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { t = new Test(); } catch (Exception e) { e.printStackTrace(); } } }); } public static void addComponentsToPane(Container pane) { JButton button; pane.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); ImageIcon icon; icon = new ImageIcon(System.getProperty("user.dir") + "/res

JLabels, that store ImageIcons, are returned back to original location when the mouse is clicked in the panel

戏子无情 提交于 2019-12-11 18:07:36
问题 I've added this listener to a JLabel, and I am able to drag the image around perfectly, However, as soon as I click on the panel(in an area where a JLabel is not present) the label returns back to it's original location. I can't figure out why that would happen. Please help me out, I've spent hours working on this. Thanks! public class CardLabelListener extends MouseAdapter { private MouseEvent initiateEvent = null; @Override public void mouseReleased(MouseEvent me) { System.err.println(

how to make java run time sizable image box

╄→гoц情女王★ 提交于 2019-12-11 16:05:27
问题 I'm making a Unicode translator in Java. I did all hard parts, but now I want to add a resizable, relocatable image to the textpane. The user must be able to resize image with its corners and drag & drop the image within the textpane where he likes. (like Microsoft Word or Photoshop) Something like this: I tried the Styled Document properties. But I couldn't find way except inserting only an ImageIcon . 回答1: May be a better choice would be not to use textPane. If you have an custom editable

ImageIcon for DefaultTableModel

空扰寡人 提交于 2019-12-11 13:59:33
问题 I'm making a program for school which you can log the systems clipboard history, my teacher said it's good so far, but I need to add images. So I got a few images to represent an image, url, text, or a folder. But when I try to .addRow with the image, it shows the source of the image and not the actual image. Here's my class public class Main extends JFrame implements ClipboardOwner { private static final long serialVersionUID = -7215911935339264676L; public final Clipboard clipboard =

Java add icon to JCalendar

夙愿已清 提交于 2019-12-11 12:28:12
问题 I'm trying to add an icon to a specific day into a JCalendar , but I can't. How can I do that? I have this code: final JCalendar calendar = new JCalendar(); JDayChooser day= calendar.getDayChooser(); day.setAlwaysFireDayProperty(true); day.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { //put icon here ImageIcon icon = new ImageIcon("icon.png"); JLabel label = new JLabel(icon); day.add(label); } Edit : I want the icon in a day. 回答1: