jpanel

How do i draw a triangle in java?

烂漫一生 提交于 2019-12-07 19:46:44
问题 Ok so first of all i know how to draw a rectangle and circles and ect with g.drawRect or g.drawOval but there is no g.drawtriangle so can you guys tell me if there is a way to draw a triangle with out me having to draw it out each side of the triangle. 回答1: You may use Graphics.drawPolygon(int[], int[], int) where the first int[] is the set of x values, the second int[] is the set of y values, and the int is the length of the array. (In a triangle's case, the int is going to be 3) Example:

How to put an image in a specific JPanel?

╄→尐↘猪︶ㄣ 提交于 2019-12-07 18:54:54
问题 I am experimenting with board games lately and now I am making a Checkers board game. However I cannon figure out how to display a chip in a cell of the GridLayout . Each cell has it's own JPanel that I assigned in a 2D Array by a FOR Loop . I need to display the image p1Chip which is just a .png in a specific JPanel , lets say it's variable name name is board[2][3] , without messing up the GridLayout . A sample code on how I can do this would be great as it will help me out understand better

Making Table With List Of JPanels ( With Applying Percentage Size Columns )

半腔热情 提交于 2019-12-07 18:26:14
问题 In this post Making Table With List Of JPanels I can make a Table with lists of panel. And this table has many features but I need to a new feature and it is applying percentage columns.It means I like to width of all columns not equals and with a array of floats determines. This is my class table : import javax.swing.*; import java.awt.*; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.Vector; public class PanelTable extends JPanel { private String data

Listening/Handling JPanel events

浪尽此生 提交于 2019-12-07 17:03:48
问题 Good evening ladies and gentlemen, I have a problem with Java Swing that I cannot solve, maybe you can help me. Here it is: I have one JFrame which uses BorderLayout, and many JPanels. Every time I need to put up a new screen (i.e. from the Main Menu, when Search button is clicked, go to the Search Menu), I simply remove the component (JPanel) which is located in the center, and put the new screen (new JPanel) in the center instead. This way, I don't call all my header and footer objects

How to draw a JPanel as a Nimbus JButton?

独自空忆成欢 提交于 2019-12-07 16:25:01
问题 In Nimbus look and feel JButtons have a very tidy and accurate look, with rounded border and nice background. I'd like to render a JPanel with the very same look (obviously it won't have pressed state etc). What are my options? 回答1: The easiest way to get "Button look" on a JPanel is probably by extending the JPanel and override paintComponent . Here is the Nimbus JButton look: And here is my implementation of a similar look on a JPanel (I added an empty border around for showing this example

How2: Add a JPanel to a Document then export to PDF

邮差的信 提交于 2019-12-07 15:29:37
问题 first post ever in any forum with regard to programming... i usually just search until i find the answer... but this time im really stuck... here's the problem... i have a JPanel, and recently discovered that itext provides you with a way to export Java GUI to PDF... i cant seem to understand itext's language nor how to add a simple JPanel to a document then export that document to a PDF... this is all i have at the moment... import java.io.FileOutputStream; import com.itextpdf.text.*; import

image loading using a JFileChooser into a JFrame

佐手、 提交于 2019-12-07 13:15:41
问题 I am trying to write a code that displays an image selected using a JFileChooser into another JFrame .I tried the following code below but only got the following errors. Exception in thread "main" java.lang.NullPointerException at javax.swing.ImageIcon.<init>(ImageIcon.java:228) at power.<init>(fCGUI.java:53) at fCGUI.main(fCGUI.java:11) Here is the code: import javax.imageio.ImageIO; import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.awt.image.BufferedImage; import

jpanel not displaying well with jframe set to gridbaglayout

帅比萌擦擦* 提交于 2019-12-07 09:47:04
问题 the program below is to position a jpanel at the top left conner of jframe with gridbaglayout but instead a very small box is displayed in center of jframe. when I set the layout of jframe to null, the jpanel displays fine. can someone tell me why the jpanel is compressed to the center of frame with gridbaglayout? i really need to use gridbag. please help import java.awt.*; import javax.swing.*; //swing package public class Major { //defining the constructor public Major() { JFrame maFrame =

How can I display an image in a JPanel

流过昼夜 提交于 2019-12-07 09:37:50
问题 My question here is how can I display an image into a JPanel? Other topics here asking something similar aren't clear to my about how can I do that. I have a directory in my project folder that have image files Project Folder/GUI/img , specifically gray.png and green.png which I want to display in a JPanel. I tried with the following code using ImageIcon and JLabel that I found in other post: ImageIcon image = new ImageIcon("GUI/img/gray.png"); JLabel label = new JLabel(image); //JPanel panel

How to implement MouseWheelListener for JPanel without breaking its default implementation?

最后都变了- 提交于 2019-12-07 07:53:25
问题 Simply; I have a JPanel inside a JScrollPane ; As expected; JScrollPane by default listens to MouseWheelEvent so that scrolling is working well for when the wheel is rotating and while the cursor is hovering over the JPanel . But After that; I just updated JPanel so that it implements MouseWheelListener , and I added this mouse wheel listener for the JPanel itself. @Override public void mouseWheelMoved(MouseWheelEvent e) { if (e.isControlDown()) { if (e.getWheelRotation() < 0) { System.out