![]() Here's some fully functioning sample code, which expects two button images, "Button-Image-Up.png" and "Button-Image-Down.png" in folder "images": import javax.swing. Examples for "/" are "src/images" or "resource/img". You create both by right-clicking on your project, "New"->"Source Folder" or "New"->"Folder". The outcome: in eclipse you need to store images underneath any "Source Folder" (such as "src") or below in a "Folder". SetFileChooserStyle(((Container)comp).After reading the above, it still took me more research to understand, where and how to place image resources, using eclipse. Public void setFileChooserStyle(Component comp) Prop.store(new FileOutputStream(JARFile), null) ĭesktop.getDesktop().open(new File(getConfig("path." number))) Ĭlass MyMouseListener extends MouseAdapter Public void WriteConfig(File file, int number) Full code of creating button and set icon: tactButton new JButton ('next tact') tSize (100, 100) tIcon (new ImageIcon ( ('/images/buttonnext.jpg'))) tactButton.addActionListener (new ProcessorNextStepListener (this)) java. String configstr = prop.getProperty(name) Return new File(jarFile.getParentFile().getPath()) PrintWriter writer = new PrintWriter(JARFile, "UTF-8") įile jarFile = new File(().getCodeSource().getLocation().toURI().getPath()) ![]() My project structure looks like this: and I have simple JButton in MainWindow class: it looks like this: tactButton new JButton('next tact') and I want to set image to this button using method setIcon. So I have question how to set icon to JButton. tIconImage((new ImageIcon(getClass().getResource("/SRC/APPICON.PNG"))).getImage()) I'm not very good in creating Swing application. tRolloverIcon (Showing top 20 results out of 315) javax.swing JButton setRolloverIcon. WriteConfig(chooser.getSelectedFile(), Integer.parseInt(tmp)) ītIcon(FileSystemView.getFileSystemView().getSystemIcon(chooser.getSelectedFile())) Best Java code snippets using javax.swing. Int confirm = chooser.showSaveDialog(null) String tmp = (String)JOptionPane.showInputDialog(null, "Whick shortcut are you going to change?", "Change shortcut", JOptionPane.INFORMATION_MESSAGE, null, options, options) Uim.put("OptionPane.cancelButtonText", "Cancel") ĬtDialogTitle("Choose save location:") ĬtDialogType(JFileChooser.SAVE_DIALOG) īutton_C.addMouseListener(new MouseAdapter() Uim.put("OptionPane.okButtonText", "OK") Uim.put("Button.background", Color.WHITE) SetFileChooserStyle(chooser.getComponents()) GetContentPane().setBackground(new Color(82,29,2)) tDefaultLocale(Locale.ENGLISH) īutton_C.setPreferredSize(new Dimension(30, 80)) Int cor_y = (int)Math.round(MouseInfo.getPointerInfo().getLocation().getY()) īutton.addMouseListener(new MyMouseListener(i 1)) Int cor_x = (int)Math.round(MouseInfo.getPointerInfo().getLocation().getX()) W.addMouseMotionListener(new MouseAdapter() W.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) Ĭor_initial_x = (int)Math.round(MouseInfo.getPointerInfo().getLocation().getX()) Ĭor_initial_y = (int)Math.round(MouseInfo.getPointerInfo().getLocation().getY()) tPreferredSize(new Dimension(80,80)) įinal JLaunch w = new JLaunch("JLaunch 1.0") Static int cor_initial_x, cor_initial_y, x1, x2 How can the icon fill the entire button (for example, having a custom size of 48x48, or automatically filled the button)? The frame will not be resized.įont f1 = new Font("Microsoft Jhenghei", Font.PLAIN, 12) įont f2 = new Font("Microsoft Jhenghei", Font.PLAIN, 48) īorder b1 = new LineBorder(Color.WHITE, 1) įile JARFile = new File(getJARPath() "\\PREF.PROPERTIES\\") įileNameExtensionFilter filter = new FileNameExtensionFilter("Executable files", "exe") However, the icons are very small and they don't fill the entire button. How can the icon fill the entire button (for example, having a custom size of 48x48, or automatically. ![]() ![]() Here the getConfig() method is already defined to get a string in a "properties" file. Get the executable icons and set them on the JButtons. Still there are some problems.ītIcon(FileSystemView.getFileSystemView().getSystemIcon(new File(getConfig("path." (i 1))))) I tried to get the executable icons and set them on the JButtons. Recently I have been working on an executable launcher. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |