Search Results

Search found 7 results on 1 pages for 'vybhav'.

Page 1/1 | 1 

  • how to reuse the area in a container when any component is removed from it?

    - by vybhav
    hi! i hav a panel and i m trying to remove labels from it which were added to it during run-time. but when labels are removed succesfully i m not able to use the space,left by that label,again to add any label to it. thanks in anticipation of the solution. here is the relevant code snippet: to add label to the panel: JLabel jl = new JLabel(); jl.setOpaque(true); jl.setIcon(new ImageIcon("D:/Project/router2.jpg")); jl.setBounds(x, y,jl.getPreferredSize().width,jl.getPreferredSize().height); for(Component c :lcomponent) { flag=true; Rectangle r4=c.getBounds(); int x1=(int) r4.getX(); int y1=(int) r4.getY(); Rectangle r5 = new Rectangle(new Point(x1-60, y1-60),new Dimension(170,170)); if(r5.contains(p)){ //To ensure that two labels do not overlap or are too close flag = false; // to each other break; }} if(flag) { p2.add(jl); //p2 is a panel Component c2 = p2.getComponentAt(x,y); p2.repaint(); lcomponent.add(c2); //lcomponent is an ArrayList<Component> to store all the labels added to the panel } 2.to remove the label: p2.remove(); p2.repaint();

    Read the article

  • How to change column width of a table

    - by vybhav
    For the following code, I am not able to set the column size to a custom size. Why is it so?Also the first column is not being displayed. import java.awt.BorderLayout; import java.awt.GridLayout; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTable; import javax.swing.table.TableColumn; public class Trial extends JFrame{ public void create(){ JPanel jp = new JPanel(); String[] string = {" ", "A"}; Object[][] data = {{"A", "0"},{"B", "3"},{"C","5"},{"D","-"}}; JTable table = new JTable(data, string); jp.setLayout(new GridLayout(2,0)); jp.add(table); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); TableColumn column = null; for (int i = 0; i < 2; i++) { column = table.getColumnModel().getColumn(i); column.setPreferredWidth(20); //custom size } setLayout(new BorderLayout()); add(jp); } public static void main(String [] a){ Trial trial = new Trial(); trial.setSize(300,300); trial.setVisible(true); trial.setDefaultCloseOperation(Trial.EXIT_ON_CLOSE); trial.create(); } }

    Read the article

  • how to disable minimize button in frame?

    - by vybhav
    can i disable minimize button in frame?how?(i hav already tried setUndecorated() and setResizable().both didnt work). i m trying to add imags to a panel at a random location which i m able to do) bt wen frame is minimized by clicking at the minimize button (not wen frame minimizes by clicking at the background window) images assemble at the top in a row. help guys..... thanks

    Read the article

  • how to draw a line between two labels in a panel where labels are added during runtime

    - by vybhav
    A panel contains two labels which are generated by mouse clicks on the panel. I want to connect these two labels by drawing a line between them probably by dragging the mouse pointer from one label to another. There are two events here - one is clicking on the panel to generate the labels and the second is connecting these two labels (mouse pressed, mouse dragged and mouse released events). Both these event need to call the repaint() method but for different purposes. But there can be only one paint() method. The problem is when I connect these two labels, the line comes up but the rest of the components on the panel disappear.

    Read the article

1