awt

How to use JFileChooser to display image in a JFrame or JPanel

对着背影说爱祢 提交于 2019-12-13 11:29:36
问题 I have created a program that can change the format of an image. Everything is working, but when I open an image through JFileChooser I am getting java.lang.ClassCastException . Please can somebody help me. I think I am making a mistake when using the file chooser. I am beginner, please can somebody help me as soon as possible? package helloWorld; import java.io.*; import java.util.TreeSet; import java.awt.*; import java.awt.event.*; import java.awt.geom.AffineTransform; import java.awt.image

Why is nothing showing up in my Java GUI?

半城伤御伤魂 提交于 2019-12-13 10:28:15
问题 I am currently working on a calculator. Right now, I am trying to gain experience with coding Java GUI, by making a simple program that makes a window with a text field. The code can compile without errors, but when I execute the program, the window appears, but without the text field. How do I make the text field visible? The code is shown as follows: import javax.swing.*; import java.awt.*; public class Window { public static void main(String[] args) { JFrame Window = new JFrame("Window");

Java Hangman GUI not properly displaying [closed]

一世执手 提交于 2019-12-13 09:49:17
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 6 years ago . I'm having a couple of different problems with my code, most of them are GUI based problems but i do have one actionevent problem. I will post my code in sections first then I will point out what the issue is specifically with each section. *note all of my code will be in order of

Using the paint or repaint method to paint lines over an applet JAVA

送分小仙女□ 提交于 2019-12-13 09:21:59
问题 I am wondering if it's possible to paint lines over an applet. I am loading the applet from an external source, but I'd like to paint lines where the cursor is on the screen. Can someone tell me how I'd do this please? Here's an example. g.drawLine(mouse.getLocation().x - 6, mouse.getLocation().y, mouse.getLocation().x + 6, mouse.getLocation().y); g.drawLine(mouse.getLocation ().x, mouse.getLocation().y - 6, mouse.getLocation().x, mouse.getLocation().y + 6); 回答1: I am wondering if it's

Highlighting the text of a jtable cell

可紊 提交于 2019-12-13 08:17:36
问题 I am trying to highlight the text of a jtable cell. This is my code: when i am getting the editor for specified cell in testingHighlighter method and trying to highlight the text in that editor component. please help me where i am wrong. public class test extends JFrame { DefaultTableModel model; JTable table; String col[] = {"Name","Address","Phone","test"}; public static void main(String args[]) { test t = new test(); t.start(); t.testingHightligher(); } public void start() { model = new

Filter not working in FileDialog

一笑奈何 提交于 2019-12-13 07:52:19
问题 I have to replace JFileChooser with FileDialog. I could not Filter out the file. Following is the code. The filter is also not visible on the Save FileDialog and also user is able to save the file file with different ext. The environment is windows 10 public class ABCDialog extends JDialog { private String fileName = StringUtils.Empty; public ABCDialog (Frame frame,String title) { super(frame, title); ..... } public String getFileName () { return fileName; } private String setFileName () {

ListSelectionListener and CardLayout

独自空忆成欢 提交于 2019-12-13 07:47:09
问题 I'm creating a program that reads data from a file, displays it on a GUI that has a JList and JButtons. I am trying to write it with CardLayout so the appropriate JPanel can be displayed when an item is selected from the JList or a JButton is clicked (i.e. next, previous, first and last). I am able to successfully read from the file and display data to the GUI. I've run into 2 problems and I've tried searching online for answers but cant seem to figure it out: 1) How do I get the JPanels to

Drawing a curve in Java using mouse drag

我的梦境 提交于 2019-12-13 07:46:52
问题 I am new to java and I am trying to draw a curve. The functionality I am trying to implement is that the curves should be defined by a mouse drag followed by a mouse click. Once the drag action is done, I want a line to be drawn from the start of the drag to the end. Clicking on the canvas after that should be considered the third point necessary to define the curve and the line drawn should be changed into a curve. How do I do that? I've gone through different posts here about how to draw

Search data in excel using Java program

牧云@^-^@ 提交于 2019-12-13 07:46:49
问题 I want to search data in excel sheet by using Java program. Condition: Write search data in text field and press Jbutton for search. Textfield data goes to excel file and find row who contain matching data. Row data copy and move to java program and Copy in 1 and more Textfield. 回答1: You better use macros to achieve this functionality. 来源: https://stackoverflow.com/questions/49964929/search-data-in-excel-using-java-program

Screen Size in Java

纵然是瞬间 提交于 2019-12-13 06:49:55
问题 Hello I am making a game in Java and I get the screenSize using DefaultToolkit, but the problem with that is that is detects the size of the screen if it was FULLSCREEN. How can I get the screen size of the area the game screen (which is not fullscreen) takes up. To be more precise, my sprite is moving beyond the edge of the bottom screen because of the system tool bar which add extra "padding" to it. How can I get the size of the Area the Game Screen takes up? Thank you very much 回答1: I