awt

PrintScreen image capturing

夙愿已清 提交于 2019-12-12 04:54:50
问题 I need to write a program that I will create a runnable jar and distribute. The functions should be like below: when double click the jar, it will open a window. it will ask the path where to save the image files. it will then ask whether to add any prefix / suffix / both on every image along with timestamp for unique name. it will also ask what image format to use. the app can be minimized and closed it will take a full screenshot whenever PrintScreen is pressed and save. Please provide a

Draw image on AWT Canvas

走远了吗. 提交于 2019-12-12 04:07:34
问题 I'm trying to draw an image on an AWT Canvas. The only line I've got this far is: Canvas canvas = new Canvas(); I'm not sure which method to use to add an image to the canvas now... I tried createImage() but didn't know how to continue with the ImageProducer... Maybe someone's got a little hint for me here? 回答1: You have several ways to do this. If you don't want to create a subclass of Canvas , add this line (where img is a subclass java.awt.Image ): canvas.getGraphics().drawImage(img, 0,0,

Printing multiple components

青春壹個敷衍的年華 提交于 2019-12-12 03:55:59
问题 I am trying to send a JTable and a JPanel to the printer in a single print job like this : PrintRequestAttributeSet attr = new HashPrintRequestAttributeSet(); attr.add(OrientationRequested.LANDSCAPE); MessageFormat header = new MessageFormat("Page {0}"); Printable p1 = table.getPrintable(JTable.PrintMode.FIT_WIDTH, header, null); PageFormat pf = new PageFormat(); Printable p2 = new ComponentPrinter().returnIt(jPanel1); Book book = new Book(); book.append(p1, pf); book.append(p2, pf);

JRootPane#setDefaultButton(theButton) does nothing

岁酱吖の 提交于 2019-12-12 03:53:17
问题 I want my only JButton in the JFrame to be the default button and respond to ENTER press anywhere in its container. So I called the JRootPane#setDefaultButton(theButton) but nothing happens: package tests; import org.junit.Test; import javax.swing.*; import java.awt.*; public class HierarchyTest { @Test public void test(){ JDialog win = new JDialog(null, "test", Dialog.ModalityType.APPLICATION_MODAL); win.setBounds(600,300,400,200); CommonPanel panel = new CommonPanel(); win.add(panel); panel

Determine the size of caption windows 7 using java AWT

故事扮演 提交于 2019-12-12 03:45:08
问题 Is their a way to determine the size of window caption using Java AWT. I just changed the caption size on my local windows 7 machine using (Start-> Control Panel -> Display ->Personalization -> Window color -> Advanced appearance settings. In the drop down select caption size and set it to 50. Any inputs on determining the caption size using Java AWT would be greatly helpful. Thanks 回答1: Here you can find a list of properties of Windows GUI and how to retrieve them. I hope you can find the

Prevent drawing over the same area of a Graphics2D

主宰稳场 提交于 2019-12-12 03:33:34
问题 Language: Java. Hi, I need to prevent drawing over the same location of a Graphics2D more than once. For example, if the user draws using a BasicStroke with a round cap and a width of 10 over a certain area, that same area cannot be drawn on a second time. The reason I want to do this is so that the user can draw (free-hand) translucent colours over an image without drawing over the same stroke (thus increasing the density of the colour and reducing its translucency). I've tried storing the

How to set label text to JTextField input

雨燕双飞 提交于 2019-12-12 03:19:20
问题 I'm trying to get a user to input a name in one panel on CardLayout and for the input to then define a JLabels text in the next panel that it switches to. I used System.out.println(userName); to double check that it was picking up the text and it definitely is but I don't know how to get the 'user' text to be that of the JTextFields input. Full working code below: import java.awt.CardLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton;

Java change JTextField size inside a GridLayout

五迷三道 提交于 2019-12-12 03:18:29
问题 I have a GridLayout(3,2) as follows with 2 JLabels, 2 JTextFields and a JButton. I add them as shown in the pic or code. Everything is just fine but the JTextField size is too big and I want it to be as shown by the red lines I've drawed. I have tried saying jtf3.setPreferredSize( new Dimension( x, y ) ); but it didn't change the dimension at all. One other solution was to make the GridLayout somewhat GridLayout(3,2,1,50) for example (by adding 50) but that moves the JLabels way top too... I

Setting the pivot point of a JPanel to its center

女生的网名这么多〃 提交于 2019-12-12 03:16:43
问题 I am building a Java application that is going to feature two circles of random sizes that need to be clicked by the user. The time between the click on the first and the second circle is going to be measured. Unfortunately, since I am new to Java so things have been slow for me. Currently I have my application draw circles and measure time between clicks using System.nanoTime() but now I am running into a problem. Because the circles need to be a fixed distance away from eachother I want to

repaint() paints slower than paintComponent()?

为君一笑 提交于 2019-12-12 03:07:39
问题 I am painting vehicle objects that I defined using the paintComponent(). Because the vehicles can move, I implement ActionListener and set a Timer() to trigger. As a result, my vehicles can move. But it is kind of "shaking". When I keep resizing the window to call the paintComponent(), the movement becomes smooth. When I do not resize the window (not calling paintComponent), it gets skaking again. Why? How to fix it? public class VehiclesComponent extends JComponent implements ActionListener{