awt

How to print a JTable object in the Java application

 ̄綄美尐妖づ 提交于 2019-11-27 05:39:19
Question Now once the data is fetched from the database and shown in the JTable object "table" embedded in the scrollPane, how do we create a print job that makes it possible to print the displayed table as such in A3 sized paper ? My code to fetch the data from the database is shown below: try { Class.forName("com.mysql.jdbc.Driver"); Connection con=DriverManager.getConnection("jdbc:mysql://localhost/newb","root","pass"); Statement stat=con.createStatement(); ResultSet res=stat.executeQuery("select * from table where name = '"+name+"'"); ResultSetMetaData rsmd = res.getMetaData(); int

How to make AWT Button() and use ImageIcon(), Icon()?

十年热恋 提交于 2019-11-27 05:38:26
How can I apply a GIF image to my AWT Button ? AWT : does not work Icon warnIcon = new ImageIcon("/src/world.gif"); Button button1 = new Button(warnIcon); Icon warnIcon = new ImageIcon("/src/world.gif"); JButton button1 = new JButton(warnIcon); woliveirajr AWT is a bit different from Swing. There's no constructor button(image) , hence your "not working". Take a look at Learn how to extend the AWT with your own image buttons to see how to make that image on a AWT button. mKorbel Back to your three days history, please try to run the code below on your native OS and by using OpenJDK (maybe it is

Mirroring animated gif on load in Java - ImageIcon

青春壹個敷衍的年華 提交于 2019-11-27 05:33:21
So I have an animated gif that I load into an ImageIcon like this: Image image = new ImageIcon("image.gif").getImage(); and I can draw it using this: g.drawImage(image, x, y, null); I know that I can mirror it on the fly using AffineTransform, but I need to be able to mirror it horizontally after loading, so that I can draw the mirrored one instead if needed without the overhead of transforming it every time it gets redrawn. Is there a way to do this using swing/awt? A library that could do this would also be a huge help. MadProgrammer The problem is, as you have pointed out, is the fact the

How can I make this JButton visible? When I have progressive scan background JWindow()?

拈花ヽ惹草 提交于 2019-11-27 05:29:33
How can I make the JButton visible? 1) When no progressive background is turned on: JButton is showing 2) When no progressive background is turned on, JButton is pressed still showing no flicker: 3) When progressive background is turned on, JButton is invisible and on pressing in this I see flicker and JButton() appears and again hides auto. << Problem is here, so how can I fix it? import java.awt.Color; import java.awt.AlphaComposite; import java.awt.BorderLayout; import java.awt.Graphics; import javax.swing.*; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java

How can a Swing WindowListener veto JFrame closing

℡╲_俬逩灬. 提交于 2019-11-27 05:27:37
I have a frame, and want to prompt when the user closes it to save the document. But if they cancel, the frame shouldn't close. frame.addWindowListener(new SaveOnCloseWindowListener(fileState)); ... public class SaveOnCloseWindowListener extends WindowAdapter { private final FileState fileState; public SaveOnCloseWindowListener(FileState fileState) { this.fileState = fileState; } public void windowClosing(WindowEvent e) { if (!fileState.onQuit()) cancelClose(); } } FileState looks at whether the document is dirty. If it isn't it does nothing and returns true. If it is dirty, it asks the user

Pacman open/close mouth animation

为君一笑 提交于 2019-11-27 05:23:22
I want to make the pacman open/close mouth animation using the easiest method. Here is my recent code: The problem is, nothing is happening? package ordner; import java.awt.Color; import java.awt.Graphics; import javax.swing.JFrame; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class PacMan implements ActionListener { private JFrame frame; private DrawPanel panel; private void initGui() { frame = new JFrame("Pacman"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); panel = new DrawPanel(); frame.add(panel); panel.setBackground(Color.BLACK); frame.setSize

Java rotating non-square JPanel component

China☆狼群 提交于 2019-11-27 05:22:55
I am attempting to rotate a GridLayout filled with text labels to simulate a portrait orientation view due to an OS restriction. The JPanel they are inside of is not square, so when rotating 90 degrees the labels cut off based on dimensions of the JPanel. Is it possible to resize the layout based on the rotation to still fit within the JPanel? Researching into this showed many options for rotations, but only for square JPanels. To further explain my problem: when I rotate the labels painted inside they stay formatted to the normal oriented x,y, and I want it to format the layout to fit into

How to eliminate delay in keyPress?

蓝咒 提交于 2019-11-27 04:55:00
问题 So I have seen a few threads about this already and I need some help about how to fix it specifically. When you hold down a key, Java will read the first key press, then there will be a small delay, and then it will continuously read the key press until you release the key. public void keyPressed(KeyEvent key) { int code = key.getKeyCode(); if (code == KeyEvent.VK_DOWN) { //Do stuff } if (code == KeyEvent.VK_LEFT) { //Do stuff } if (code == KeyEvent.VK_RIGHT) { //Do stuff } if (code ==

best example for programmatically creating SplashScreen with text

好久不见. 提交于 2019-11-27 04:54:10
问题 I need to create a SplashScreen programmatically and add text to it (and change it). Most examples work with thecommand line parameters. Are there solutions working without? 回答1: You can use an undecorated dialog with a background image and a progress bar while loading stuffs in a SwingWorker. When done, hide the dialog and start the UI as usual. Components added to the dialog/splashcreen must be non-opaque in order to "see" the background image. Here is a working example: import java.awt

How to rotate a rectangle after reaching specified position?

自古美人都是妖i 提交于 2019-11-27 04:52:40
问题 I would like to rotate a rectangle when e.g. y position achieve specified position. I would like to behave a rectangle as a car on a junction - just turn e.g. right. I prefer just rotate and continue. A draft code looks like that: Graphics2D g2d = (Graphics2D) g.create(); g2d.setPaint(new Color(150, 150, 0)); //1. when rectangle achieve 500 on y dimension just rotate left/right if(y==500) { _rotate = true; g2d.rotate(Math.toRadians(90.)); } if(_rotate) { //if rotate, continue way on x